I have a doubt for example if i have an input like this :
5 4
1 2 3 4 5
2 3 4
2 3
1 2 3
Where the first number means the different "toys" there are to attribute to each kid which corresponds to the second number which is four and by consequence to the number of lines that represents each kid and the toys they want ...
How would i read an input like this in ansi C?
With the use of strtok? or is there any other simpler way to do it?
i could do it with something like this
char line [250];
char * tok;
char *ptr = line;
while((scanf("%s",line)!= EOF){
while ((tok = strtok(ptr, " ")) != NULL)
{
pseudo part
//convert to int
//add to array
}
}
but is there any easier way to do this input without using tok? Thanks ...
ptrsupposed to be riddle?strtok? Successive calls use NULL instead of the original value.scanf("%s", line)isn't going to read a line, it's going to read a whitespace delimited string, so you don't needstrtok.