[問題] 自己寫的亂數程式碼 有地方錯誤沒辦法執行

看板C_and_CPP (C/C++)作者 (robinson)時間16年前 (2009/09/02 20:10), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串1/1
打完後按執行 卻沒辦法編譯 一直顯示程式碼有地方錯誤 所以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

09/02 20:40, , 1F
strcmp(str,"OPEN")==0 要用這函式
09/02 20:40, 1F

09/02 21:08, , 2F
輸入CLOSE的話字串夠長嗎?
09/02 21:08, 2F

09/04 17:36, , 3F
不夠 最後會多個 '\0' ?
09/04 17:36, 3F
文章代碼(AID): #1Adc2bYf (C_and_CPP)
文章代碼(AID): #1Adc2bYf (C_and_CPP)