My function is not quite done yet, but what I'm going to do is:
- To read in a string of numbers separated by spaces.
- Extract the numbers from that string.
- Convert them to long ints.
Return the number of numbers read in.
int input( int a, int b, long int *result_array ) { int ele = 0; char buffer[200]; char *start, *end; scanf("%[^\n]%*c", buffer ); start = buffer; while( ( end = ( strchr( start, ' ' ) ) != NULL ) ) { result_array = strtol( start, &end, 10 ); ele += 1; start = end + 1; } return ele; }
It doesn't seem to work properly, I think I'm using strchr wrong.