作者p122128 (robinson)
看板C_and_CPP
标题[问题] 自己写的乱数程式码 有地方错误没办法执行
时间Wed Sep 2 20:10:12 2009
打完後按执行 却没办法编译 一直显示程式码有地方错误
所以PO上来跟大家讨论
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string>
void aaaa();
int main()
{
char str[5];
while(1)
{
printf("输入OPEN产生,输入CLOSE结束此程式:");
scanf("%s",&str);
if((str=="OPEN")||(str=="open"))
aaaa();
else if((str=="CLOSE")||(str=="close"))
break;
else printf("您输入错误,请重新输入。\n");
}
system("pause");
return 0;
}
void aaaa()
{
int x;
srand(time(NULL));
x=(rand()%5)+1;
switch(x)
{
case 1:
printf("A");
break;
case 2:
printf("B");
break;
case 3:
printf("C"); break;
case 4:
printf("D");
break;
default:
printf("E");
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.115.217.2
1F:→ tocute:strcmp(str,"OPEN")==0 要用这函式 09/02 20:40
2F:→ genki:输入CLOSE的话字串够长吗? 09/02 21:08
3F:→ walker2009:不够 最後会多个 '\0' ? 09/04 17:36