I was wondering how to extract various numbers from a string. I understand that strtol works, however it appears to only work for the first digit.
Here is my code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(){
long v1, v2, v3;
char str[20] = "16,23";
char *d;
v1 = strtol(str, &d, 10);
v2 = strtol(str, &d, 10);
printf("string is %s\nv1 is:%i\nv2 is:%d\n",str , v1,v2);
return 0;
}
In this example I would like to output v1 = 16 and v2 = 23.
Another example, if the str was "12,23,34", I would like v3= 34
Thanks in advance :)