恕直言,你的代码没法看下去。给你写一个你对照看,有注释。
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
int main(void){
char a[50];
int i;
while(1){
printf("Pleale input a string(## end)...\nstr=");
if(gets(a),a[0]=='#' && a[1]=='#')//输入了两个##则结束
break;
if(!(a[0]>='a' && a[0]<='z' || a[0]>='A' && a[0]<='Z' || a[0]=='_'))//不以字母或下划线开头则不是
printf("\'%s\' --- NO!\n",a);
else{
for(i=1;a[i];i++)//中间若有不是字母、数字、下划线的则不是
if(!(a[i]>='a' && a[i]<='z' || a[i]>='A' && a[i]<='Z' || a[i]=='_' || a[i]>='0' && a[i]<='9')){
printf("\'%s\' --- NO!\n",a);
break;
}
if(a[i]=='\0')//排除以上情况剩下的肯定是
printf("\'%s\' --- YES!\n",a);
}
}
return 0;
}
合法标示符是由字母,数字,下划线组成,开头不能是数字
还有一点,标示符不能用C的关键字
楼上的代码好像遗漏了这方面的判断
楼主认为,什么是《C的合法标识符》?
ccchart,是不是合法的标志符 ?
输入一个字符串,楼主是怎么接收的 ?