You'll probably want to do some range checking also...
Code:
/* return 0 on success */
int parse_ulint(const char * buffer, unsigned long int * dest)
{
unsigned long int tmp = 0;
char * ep = NULL;
assert(buffer != NULL);
assert(dest != NULL);
/* reset errno and attempt to parse */
errno = 0;
tmp = strtoul(buffer, &ep, 10);
if(buffer[0] == '\0' || *ep != '\0')
{
return -2; /* not a number */
}else if(errno == ERANGE && tmp == ULONG_MAX){
return -3; /* range error */
}else if(errno != 0){
return -1; /* some other error */
}
/* store the parsed value */
*dest = tmp;
return 0; /* success */
}
Of course if you just want integers, then just check for INT_MAX or INT_MIN (and use strtol instead of strtoul) from limits.h and return failure if the long int is outside of that range.
Then all you need to do is read with fgets() as others suggest.