Using strtoul() to convert string to an unsigned long-integer value
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info:
To do: Converting a string to an unsigned long using strtoul() C function
To show: How to use strtoul() C function in converting string to unsigned long with 3 argument
// Using strtoul() /wcstoul()- converting string to unsigned long with 3 arguments
#include <stdio.h>
int main(void)
{
unsigned long x;
char *thestring = "1234567def", *remainderPtr;
x = strtoul(thestring, &remainderPtr, 0);
printf("Using strtoul() - converting string to\n");
printf(" unsigned long, 3 arguments\n");
printf("---------------------------------------\n\n");
printf("The original string is \"%s\"\n", thestring);
printf("The converted value is %lu\n", x);
printf("The remainder of the original string is \"%s\"\n", remainderPtr);
printf("The converted value, %lu minus 567 is %lu\n", x, x - 567);
return 0;
}
Output example:
Using strtoul() - converting string to
unsigned long, 3 arguments
---------------------------------------
The original string is "1234567def"
The converted value is 1234567
The remainder of the original string is "def"
The converted value, 1234567 minus 567 is 1234000
Press any key to continue . . .