Pages

Saturday, January 30, 2016

C program to separate words (tokens) from a given string

#include<stdio.h>
#include<stdlib.h>
int main()
{
      char str1[80]="Hello Student How are you?";
   const char str[80] = "", s[2] = " ";
   char *token;
   int counter=1;
   
   token = strtok(str1,s);
   while (token != NULL)
   {
printf("Token %d = %s \n", counter++, token);
token = strtok(NULL, s);
   }
   return 0;
}

Output of program

Token 1 = Hello
Token 2 = Student
Token 3 = How
Token 4 = are
Token 5 = you?


You may also like to learn following programs:

No comments:

Post a Comment