已知C源程序如下: /**************************************************/ /* 功能:检查输入的标识符是否符合C语言规则 */ /**************************

admin2011-01-12  28

问题 已知C源程序如下:
   /**************************************************/
   /*  功能:检查输入的标识符是否符合C语言规则  */
   /**************************************************/
   #include<stdio.h>
   #include<string.h>
   #include<ctype.h>
   #include<conio.h>
   #include<malloc.h>
   char*IsLegal(char*CheckWorD) ;
   const int MaxWordLen=32;
   char*ErrorMessages[]={    /*错误信息列表*/
   "合法!",
   "首字符只能是字母或下划线!",
   "常、变量只能由字母、下划线和数字构成!",
   "常、变量标识不能用C语言关键字!"。
   "常、变量标识不能用C语言预定义函数名!",
   "内存不够!"
   };
   int main()
   {
   char*Prompt="C语言标识符的命名要遵守以下原则:";
   char*TestWord;
   int i;
   TestWord=(char*)malloc(sizeof(char)*MaxWordLen);
   /*TestWord存放用户输入*/
   if(!TestWorD)
   return 1;
   /*显示部分提示信息*/
   puts(Prompt);
   for(i=1;i<=4;i++){
   puts(ErrorMessages);
   }
   while(1){
   printf("\n\n请输入一个标识符(大写的Q退出):");/*提示*/
   scanf("%s",TestWorD) ;                         /*得到用户输入*/
   if(toupper)(TestWord[0]))==’0’)
   break;                                         /*循环出口*/
   prind("\n%s  %s",TestWord,IsLegal(TestWorD) );/*判定标识符的合法性*/
   }
   free(TesfWorD) ;
   return 0;
   }
   /*此函数检验标识符命名的合法性*/
   char*IsLegal(ehar*CheckWorD)
   {
   char*KeyWords[]={"auto","break","case","char","continue","const","default",
   "do","double","else","enum",extern","float","for","goto",
   "if","int","long","noalias","register","return","short",
   "signed","sizeof","static","struct","switch","typedef",
   "union","unsigned","void","volatile","while","defined",
   "define","undef","include","ifdef","ifndef","endif","line",
   "error","elif","pragma"};    /*C关键字列表*/
   char*Functions[]={"close","crest","eof","fclose","fcloseall","feof","fopen",
   "ferror","fgetchar","fgets","fprintf","fputc","fputchar",
   "fseek","get","putch","putc","printf","open","putchar",
   "puts","read","scanf","abs","acos","asin","math","atan",
   "atan2","atof","atoi","atol","ceil","dos","cosh",ecvt",
   "exp","fabs","floor","fmod","frexp","itoa","labs","ldexp",
   "log","log10","modf","pow","rand","sin","sqrt","srand",
   "strtod","strlol","tan","tanh","ultoa","memset","strcpy",
   "strcat","strchr","strcrap","calloc","isalnum","isalpha",
   "toascii","tolower","tollpper","exit");  /*C主要预定义函数列表*/
   char*Others="_";    /*’_’也可以用于关键字,但我们不推荐您使用!*/
   int WordLength,i;
   char*WordTemp;
   WordLength=strlen(CheckWorD) ;
   /*检查标识符命名原则1*/
   if((isalpha(CheckWord[0])==0)&&(CheckWord[0]!=Others[0]))
   return ErrorMessages[1];
   /*检查标识符命名原则2*/
   for(i=0;i<WordLength;i++)
   if((isalnum(CheekWord==0)&&(CheckWord!=Others[0]))
   return ErrorMessages[2];
   /*检查标识符命名原则3*/
   for(i=0;i<44;i++)
   {
   if(!strcmp(CheckWord,KeyWords))
   return ErrorMessages[3];
   }
   /*检查标识符命名原则4 */
   for(i=0;i<69;i++)
   {
   if(!stremp(CheckWord,Functions))
   return ErrorMessages[4];
   }
   return ErrorMessages[0];
   }

参照QESAT/C软件分析与测试工具的规定,画出程序中所有函数的控制流程图;

选项

答案[*]

解析
转载请注明原文地址:https://jikaoti.com/ti/sPE7FFFM
0

相关试题推荐
最新回复(0)