Untitled
unknown
plain_text
2 years ago
1.1 kB
18
Indexable
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
bool iskeyword(char * str){
char keyword[32][10]={
"auto","double","int","struct","break","else","long",
"switch","case","enum","register","typedef","char",
"extern","return","union","const","float","short",
"unsigned","continue","for","signed","void","default",
"goto","sizeof","voltile","do","if","static","while"
};
bool flag=false;
for (int i=0; i <32; i++)
{
if (strcmp(str,keyword[i])==0)
{
flag=true;
}
}
if (flag==true)
{
return true;
}
return false;
}
int main(){
char word[20];
char str[]="Hello if else and while continue if ";
int i,j=0;
for (i=0;str[i]!='\0'; i++){
if (str[i]==' '){
word[j]='\0';
if(iskeyword(word)==true){
printf("%s is keyword\n",word);
}
j=0;
printf("%s",word);
}else{
word[j]=str[i];
j++;
}
}
}Editor is loading...
Leave a Comment