Aim:
Write down program for separating lexemes’ to the given input.
#include<stdio.h>
#include<conio.h>
void main()
{
      char str[100],lex[50][50];
      int i,j,k,l=0,m=0;
      clrscr();
      printf("\n\n===========LEXEME================");
      printf("\n\n\nEnter the string
===> ");
      gets(str);
      for(i=0;str[i]!=NULL;i++)
      {
            if(str[i]!=' ')
            {
                  lex[l][m]=str[i];
                  m++;
            }
            else
            {
                  lex[l][m]=NULL;
                  l++;
                  m=0;
            }
      }
      lex[l][m]=NULL;
      printf("\n\n\t");
      for(i=0;i<=l;i++)
      {
            for(j=0;lex[i][j]!=NULL;j++)
            {
                  printf("%c",lex[i][j]);
            }
            printf("\n\n\t");
      }
      getch();
}
output:
 
No comments:
Post a Comment