Write a program in C that extracts the tokens from a string.
Given a string as input, the program should print on the screen
each token on a new line. For example given the following string as
input: “hello there my friends” the program should generate:
I
am
a
programmer
#include<stdio.h>
#include <string.h>
int main() {
char string[50];
printf("Enter string\n");
gets(string);
char * token = strtok(string, " ");
while( token != NULL ) {
printf( "%s\n", token ); //printing each token
token = strtok(NULL, " ");
}
return 0;
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Get Answers For Free
Most questions answered within 1 hours.