I couldn't print the whole output in a string.
All I know is that %s should work like a loop for example printf("%s", str); works the same as puts(str);
#include <stdio.h>
#include <string.h>
int main (){
char str[]="Hello:, student; how are you? This task is easy!";
char *token;
char del[] = ", ; : ? !", cp[80];
int count;
strcpy(cp, str);
token = strtok(str, del);
count = 0;
while( token != NULL )
{
printf("%s\n", token);
token = strtok(NULL, del);
count++;
}
strtok(str, del);
printf("Your sentence has %d words\n", count);
puts("The sentence without punctuation charachters is: \n ");
puts(str); // This should where it show me the output
return 0 ;
}
// I tried to follow the instruction I had to write this code in this form. // This is the output that I suppose to get
Hello
student
how
are
you
This
task
is
easy
Your sentence has 11 words The sentence without punctuation characters is: Hello student how are you This task is easy
// all I got is ( ignore the extra line between each word)
Hello
student
how
are
you
This
task
is
easy
Your sentence has 11 words The sentence without punctuation characters is: Hello