C Reference function strtoul()
This function of stdlib will convert a string to an unsigned long integer.
Usage of strtoul():
unsigned long int strtoul ( const char * str, char ** endptr, int base );
Parameters:
C string str interpreting its content as an unsigned integral number of the specified base, which is returned as an unsigned long int value.
Return value:
The function returns the converted floating point number as a unsigned long int value, if successful.
If no valid conversion could be performed then an zero value is returned.
If the value is out of range then ULONG_MAX is returned.
Source code example of strtoul():
#include<stdio.h>
#include<stdlib.h>
int main ()
{
char buffer[256];
unsigned long ul;
printf ("Enter an unsigned number: ");
fgets (buffer,256,stdin);
ul = strtoul (buffer,NULL,0);
printf ("Output: %lu\n",ul);
return 0;
}
Output of the strtoul example program above:
Enter an unsigned number: 12
Output: 12
This entry was posted in C Reference stdlib.h Functions.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Tweet This! or use
to share this post with others.