Eduardo Costa answers , but he loses his memory. Better define a function to take care of this for you:
int readint(char *p, char **e)
{
char *c = readline(p);
int i = strtol(c, e, 0);
if(e)
{
size_t o = (size_t)(*e - c),
l = strlen(*e) + 1;
*e = malloc(l);
memcpy(*e, c + o, l);
}
free(c);
return i;
}
This version will even save any extra stuff on the line so you can use it later if you need it. Of course, if you need to do a lot with additional materials, you might be better off just reading the line and parsing it yourself, rather than performing such functions.
source
share