C语言求助:简短的几句代码编译出错,高手帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:59:42
#include <stdio.h>
void main()
{
char comm[100];
scanf("%s",&comm);
while()/*无限循环*/
{
switch (comm)
{ case "exit" :exit(0);break;
case "show" :printf("Now is the content\n");break;
default :printf("Command Not Found\n");
}
scanf("%s",&comm);
}
}

#include"stdio.h"
#include"string.h"
#include"stdlib.h"
void main()
{
char comm[100];
printf("请输入:");
while(1)//字符串用字符串比较函数
{
gets(comm);
if(strcmp(comm,"exit")==0)
{exit(0);
break;
}
if(strcmp(comm,"show" )==0)
{printf("Now is the content\n");
break;
} else
printf("Command Not Found\n");
}
}

将其中的
scanf("%s",&comm);
全部改为
scanf("%s",comm);

数组名字就是地址 无需其地址符号'&'

scanf("%s",&comm);
改为scanf("%s",comm);以%s格式输入只须输入数组名就行了

#include <stdio.h>
void main()
{
char comm[100];
scanf("%s",&comm);
while(1)
{
switch (comm[100])
{ case 'exit' :exit(0);break;
case 'show' :printf