Hello,
I am trying to tokenize an input txt file by spaces.
My code for it is:
Code:
while ( fgets (input, LENGTH, inputTxt))
{
token = strtok(input, " ");
while(token)
{
printf("@%s@\n", token);
token = strtok(NULL, " ");
}
}
As shown I have printed out the tokens encapsulating them with @ symbols.
The issue is that if the input text line is "Our joy advance,"
My output is
Code:
@Our@
@joy@
@advance,
@
My problem is with the last token "advance," the @ symbol shows that the token include a new line \n or maybe it's \0.
I want to send my tokens to another function, but i'm worried the last word of a line includes the \n in it's token.
Is there a way to just get the word by itself?