[cs631apue] Size of large ints

Paul-Anthony Dudzinski pdudzins at stevens.edu
Sun Oct 13 21:08:40 EDT 2013


I ended up doing this:


        char filesize[100];
        sprintf(filesize, "%ld", a->fts_statp->st_size);

        nlen_size = strlen(filesize);
        if (nlen_size > len_size)
                len_size = nlen_size;


It's not pretty, and it only supports integers 100 chars long but I will
probably end up setting it as a constant at the top of my program so it can
be easily changed. It also has the distinct advantage of working.


On Sun, Oct 13, 2013 at 7:33 PM, yluo4 <yluo4 at stevens.edu> wrote:

> I think you can use following code:
>
>  len = 1;
>  while (size / 10) {
>   len++;
>  }
>
> to get the len of the size.
>
>
> On 10/13/2013 5:06 PM, Paul-Anthony Dudzinski wrote:
>
>> Hey all,
>> I am looking for a good way to measure the size of a large integer for
>> instance when I run my program on /tmp I get:
>>
>> pdudzins at gits:~/cs631/midterm$ ./a.out -l /tmp
>>
>> drwxrwxrwx  2 root     root          4096 .X11-unix
>> -rw-------  1 jschauma professor    10724 1
>> drwxr-xr-x  3 swatts   student       4096 VisualGDB-RW-------  1
>> JSCHAUMA PROFESSOR 2097152000 BIG
>>  -rwxr-xr-x  1 swatts   student         56 dump-gdb-settings
>> -rw-r--r--  1 jschauma professor     2041 f
>> -rw-------  1 jschauma professor     2041 file
>> drwxr-xr-x  2 jsexton  student       4096 hsperfdata_jsexton
>> drwxr-xr-x  2 lxiong   student       4096 hsperfdata_lxiong
>> drwxr-xr-x  2 snatara1 student       4096 hsperfdata_snatara1
>> -rw-------  1 fcannava professor      611 krb5cc_11084_S26665
>> -rw-------  1 jrisi    student        605 krb5cc_11492_u17070
>> -rw-------  1 pdudzins student        611 krb5cc_11909_Iq7884
>> drwx------  2 jschauma professor     4096 ssh-OkXFz27774
>>
>> And the bolded line is messing up my column print lengh. When I
>> measure the size of the size I am doing it like this:
>>
>>         nlen_size =  sizeof(a->fts_statp->st_size)**;
>>         if (nlen_size > len_size)
>>                 len_size = nlen_size;
>>
>> And I keep getting 8 instead of 10 which I am pretty sure the 8 bytes
>> it takes to store an int...
>>
>> Has anyone tried casting this as a character array and taking the size
>> that way? Is there a library function that will just do this?
>>
>>
>> ______________________________**_________________
>> cs631apue mailing list
>> cs631apue at lists.stevens.edu
>> https://lists.stevens.edu/**mailman/listinfo/cs631apue<https://lists.stevens.edu/mailman/listinfo/cs631apue>
>>
> ______________________________**_________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/**mailman/listinfo/cs631apue<https://lists.stevens.edu/mailman/listinfo/cs631apue>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20131013/0432fce7/attachment.html>


More information about the cs631apue mailing list