#include <stdio.h>
#include <string.h>
void string2Lines(char line[], char tokens[]){
char *token_ptr, token[81];
char *i=";" " " "," "." "?" "!";
token_ptr = strtok(line, i );
while(token_ptr){
strcpy(token, token_ptr);
strcat(tokens, strcat(token,"\n"));
token_ptr = strtok(NULL, i );
}
}
int main(){
char sentence[81], words[81];
printf("Enter a sentence: ");
gets(sentence);
string2Lines(sentence,words);
puts(words);
}
How to write a function called findNextToken() that does the same thing as strtok() used above.
It will have three arguments:
(i)The string from which to extract tokens.
(ii)The current index position inside this string at the time of the call. This argument will be sent by reference, since its position will inevitably move past the word that is being extracted.
(iii)The token found, if any. This will return the token the value 1 if a token is found; otherwise it will return 0.