c - Iterating with sscanf -
i not know sscanf function, trying iterate through line of integers. given variable
char *lineofints
i have made line registers users input. able input fine, when try use sscanf, want iterate through every int. know can account through ints if know how many ints there before hand this..
sscanf(lineofints, "%d %d %d..etc", &i, &j, &k...)
but if don't know how many integers user input? how can account of integers 1 variable? like
sscanf(lineofints, "%d", &temp); //modifying int // jump next int , repeat
thanks!
maybe :
#include <stdio.h> int main(void) { const char * str = "10 202 3215 1"; int = 0; unsigned int count = 0, tmp = 0; printf("%s\n", str); while (sscanf(&str[count], "%d %n", &i, &tmp) != eof) { count += tmp; printf("number %d\n", i); } return 0; }
Comments
Post a Comment