、输入一个字符串,判断它是否是合法的C语言标识符,如果是,输出“it is a legal identifier.”,如果不是,输出“it is a illeg
如题
#include<stdio.h> #include<string.h> main() { char a[32][10]={"auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while"}; int i,x=1; char in[30];/*长度30应该够了*/ printf("请输入一串字符串判断是否为合法标识符:\n"); gets(in); if(in[0]=='_'||(in[0]>='a'&&in[0]<='z')||(in[0]>='A'&&in[10]<='Z')){//3 for(i=0;i<32;i++){//2 if((strcmp(a[i],in))==0){//1 x=0; break; }//1 }//2 }//3 if(x==0) printf("no"); else printf("yes"); }
#include<stdio.h> #include<string.h> main() { char a[32][10]={"auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while"}; int i,x=1; char in[30];/*长度30应该够了*/ printf("请输入一串字符串判断是否为合法标识符:\n"); gets(in); if(in[0]=='_'||(in[0]>='a'&&in[0]<='z')||(in[0]>='A'&&in[10]<='Z')){//3 for(i=0;i<32;i++){//2 if((strcmp(a[i],in))==0){//1 x=0; break; }//1 }//2 }//3 if(x==0) printf("it is a illeg.\n"); else printf("it is a legal identifier.\n"); }