回复 13楼 蚕头燕尾
我使用的编译器是GCC,基本支持C99吧,至于这段代码在我的电脑里是不显示错误的,只是在运行时进行某一些步奏会直接崩溃;例如addone后deleteone 会直接崩溃,遍历也会,可能是存在一些逻辑上的错误 - -,反正我的编译器是发现不了,只能靠调试了,还有你提出的关于枚举型的问题,下面这段代码在我的编译器里是可以正常运行的;
程序代码:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
enum allchoices {addone,deleteone,itemcount,search,showall,cleanall};
const char * choices[]={"addone","deleteone","itemcount","search","showall","cleanall"};
#define LEN 15
void menu(void);
void AddOne (void);
void DeleteOne(void);
void Itemcount(void);
void FindOne(void);
void ShowAll(void);
void CleanAll(void);
int main(void)
{
char yourchoice[LEN];
enum allchoices choice;
bool the_order_iseffective=false;
menu();
while(strcmp(gets(yourchoice),"quit")!=0&&yourchoice[0]!='\0')
{
for(choice=addone;choice<=cleanall;choice++)
{
if(strcmp(yourchoice,choices[choice])==0)
{
the_order_iseffective=true;
break;
}
}
if(the_order_iseffective)
switch (choice)
{
case (addone): AddOne();
break;
case (deleteone):DeleteOne();
break;
case(itemcount):ItemCount();
break;
case(search):FindOne();
break;
case(showall):ShowAll();
break;
case(cleanall):CleanAll();
break;
}
else
printf("i don\'t know what the order mean!\n");
the_order_iseffective=false;
puts("next order\n");
menu();
}
puts("good job\n");
return 0;
}
void menu(void)
{
puts("please chioce what do you want to to?\n");
puts("enter \"addone\" to add a classmate.\n");
puts("enter \"deleteone\" to delete a classmate\n");
puts("enter \"itemcount\" to konw the number of your classmatas\n");
puts("enter \"search\" to find your classmate\n");
puts("enter\"showall\"to printf all of your classmates.\n");
puts("enter \"cleanall\"to chean all items. \n");
puts("enter \"quit\" to quit\n");
return 0;
}
void AddOne (void)
{
printf("just like this.\n");
}
void DeleteOne(void)
{
printf("just like\n");
}
void Itemcount(void)
{
printf("just like2\n");
}
void FindOne(void)
{
printf("just like 3\n");
}
void ShowAll(void)
{
printf("just like 4\n");
}
void CleanAll(void)
{
printf("just clean all\n");
}
所以这方面应该不会出现问题;你的编译器可能不支持C99,不过添加下面代码应该可以通过编译的,
#define bool int
#define true 1
#define false 0
删除掉#include<stdbool.h>
[
本帖最后由 那小扎 于 2013-6-14 12:33 编辑 ]