Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
811 B
2
Indexable
Never
#include<stdio.h>
#include<stdbool.h>
#include<string.h>

bool iskeyword(char * word){
  char keyword[32][10]={"if","else","do","while","contine"};
  for (int i = 0; i < 32; i++)
  {
    if (strcmp(keyword[i],word)==0)
    {
      return true;
    }
  }
  return false;
}
int main(){
  char string[50];
  char word[20];
  printf("Enter the string: ");
  gets(string);
  int j=0;
  for (int i = 0; string[i]!='\0'; i++){
    if (string[i]==' ')
    {
      word[j]='\0';
      if (iskeyword(word)==true)
      {
        printf("%s is a keyword\n",word);
      }
      j=0;
    }
    else{
      word[j]=string[i];
      j++;
    }
  }
  if (j!='\0')
  {
    word[j]='\0';
    if (iskeyword(word)==true)
    {
      printf("%s is a keyword",word);
    }
    
  }
  
}
Leave a Comment