#include <stdlib.h>
unsigned long strtoul( const char *start, char **end, int base );
函数基本等同 strtol(), 不同的是,它不仅可以返回长整型数,而且可以返回无符号的长整型数。
#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* strtoul */
int main ()
{
char buffer [256];
unsigned long ul;
printf ("Enter an unsigned number: ");
fgets (buffer, 256, stdin);
ul = strtoul (buffer, NULL, 0);
printf ("Value entered: %lu. Its double: %lu\n",ul,ul*2);
return 0;
}输出结果:
Enter an unsigned number: 1000 Value entered: 1000. Its double: 2000