int index = 0;
for (char *tp = strtok(strings, " "); tp != NULL; tp = strtok(NULL, " \t\n")){
}
Let's say strings[] is something like "Today is nice," the first token return would be "Today" right? But doesn't strtok() return a pointer?
So if I want to loop through the word "Today" to print each letter out, how would I do that? Could I just do tp[index]?
You probably want this:
Yes
strtok()return a pointer. The first call tostrtok(somestring, ...)returns the pointer to the first substring, and the following calls tostrtok(NULL, ...return the next substrings.If you want to do it the hard way (the way you suggested) you can do this:
I suggest you read again the chapter dealing with strings in your C learning material.