C语言判断输入是否为C语言标识符

#include<stdio.h>
#define N 21
void isLegal(char *p)
{
 if (*p >= '0'&&*p <= '9')
 {
  printf("illegal ");
  return;
 }
 else
  while (*++p)
   if (!(*p >= 'a'&&*p <= 'z' || *p >= 'A'&&*p <= 'Z' || *p >= '0'&&*p <= '9' || *p == '_'))
   {
    printf("illegal ");
    return;
   }
 printf("legal ");
}
int main()
{
 char s[N], *p = s;
 int i;
 for (i = 0;getchar()==' '; i++)#
 {                #
  s[i]=getchar();         #
 }               #
 isLegal(s);
 return 0;
}

/*  其中#标识的代码可以简化为 gets(s); */

原文地址:https://www.cnblogs.com/didiaoxiaoguai/p/6720782.html