Home > Article > Backend Development > C program to check if a given string is a keyword?
Keywords are words that are predefined or reserved in the C library, have a fixed meaning, and are used to perform internal operations. The C language supports more than 64 keywords.
Each keyword exists in lowercase letters, such as auto, break, case, const, continue, int, etc.
The 32 keywords in C language can also be used in C language.
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 | volatile |
do | if | static | while |
##This is in C The newly added 30 reserved words are not in C language.
dynamic_cast | namespace | reinterpret_cast | |
explicit | new | static_cast | |
false | operator | template | |
friend | private | this | |
inline | public | throw | |
mutable | protected | true | |
typeid | typename | using | |
using | wchar_t |
Input: str=”for” Output: for is a keyword
Explanation
Example
#include <stdio.h> #include <string.h> int main() { 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" } ; char str[]="which"; int flag=0,i; for(i = 0; i < 32; i++) { if(strcmp(str,keyword[i])==0) { flag=1; } } if(flag==1) printf("%s is a keyword",str); else printf("%s is not a keyword",str); }
Output
which is a keyword
The above is the detailed content of C program to check if a given string is a keyword?. For more information, please follow other related articles on the PHP Chinese website!