Re: Long long int's and sprintf

From: Peter Ajamian (
Date: 06/17/01

Mike Stilson wrote:
> It does have strtoull defined in there though, and it does link, just
> requires me to fill in the ptr & base for it to work right.
> in other words, can't just do:
> unsigned long long int var; var=strtoull(from);

That's because that's not how strtoull() works.

> have to do
> unsigned long long int var; var=strtoull(from, NULL, 10);

That's how strtoull() is supposed to work.

Note that shoving a char * in for that NULL comes in handy at times for
parsing, might wanna try it when you have more than one value on a line,
you can do something like this...

unsigned long long l, m, n;
char *ptr = buf;

l = strtoull(ptr, &ptr, 10);
/* maybe this number is hex? */
m = strtoull(ptr, &ptr, 16);
/* Maybe the last number is octal? */
n = strtoull(ptr, NULL, 8);

The hex and octal options can come in handy because it's easier to
directly read bits off an ascii pfile with those.  You could even use 2
for the base to represent binary and store the bits in binary format
(being practically the easiest of all to recognize when reading as
text).  Note that a base of 0 is used for a sort of auto-detect as

If base == 0, then a leading 0x or 0X indicates a hexadecimal (base 16)
integer, a leading 0 indicates an octal (base 8) integer, and any other
valid pattern indicates a decimal (base 10) integer.

Regards, Peter

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/05/01 PST