I am trying to split an array up into tokens, an array that is input by the user, and from those tokens extract numbers only. Here is my code so far, but I am having some problems. It prints out the numbers but also some other stuff... Here is the code and the output.
#include <stdio.h>
#include <stdlib.h>
int main() {
char delimiters[] = " \t\n\r";
char storage[100];
char copy[100];
int* p;
int n=0, numbers;
for( n=0; storage[n] != EOF; n++ ) {
fgets( storage, sizeof(storage), stdin );
strcpy(copy, storage);
p = strtok(copy, delimiters);
while (p) {
sscanf(p, "%d", &numbers);
printf("%d\t", numbers);
p = strtok(NULL, delimiters);
}
printf("\n");
}
}
Output:
% gcc -o test test.c
test.c: In function `main':
test.c:15: warning: assignment makes pointer from integer without a cast
test.c:17: warning: passing arg 1 of `sscanf' from incompatible pointer type
test.c:19: warning: assignment makes pointer from integer without a cast
% test
hey 3are some 23 numbers
3 3 3 23 23
Ive been over this for the past few days and cant seem to get anywhere, nor can i find anything in my books. Thanks for your time and help in advance!