[問題] 顯示結果的問題...

看板C_and_CPP作者時間15年前 (2009/07/20 00:13), 編輯推噓2(208)
留言10則, 4人參與, 最新討論串1/1
#include<stdio.h> #include<iostream> typedef struct PersonStruct{ int id; char nickName; }Person; typedef char Str20[20]; Person persons[100]; int ints[100],ints1[100]; int ints2[100]={11,22,33,44}; Str20 names[100],name1[100]; Str20 names2[100]={"33","44","55","66","77"}; int i,a,b; Str20 str,str1,str2; char ch[100],ch1[100]; char ch2[100]={'x','y','z','w'}; int main(int argc,char*argv[]) { for(i=0;i<10;i++) ch[i]='m'; bool ok=true; for(i=0;i<10&&ok;i++){ scanf("%s",str); if(str[1]<'m') ok=false; else ch[i]=str[0]; } printf("%s %d\n",str,ch[i]); system("PAUSE"); return 0; } 輸入:one two three four five six seven eight nine ten 結果:three 87 ch[i]那幾行看不是很懂?@@有大大能幫小弟解惑嗎?? ...(因為不知道87怎麼來的? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.126.155.60

07/20 00:29, , 1F
我也不知道那個ok是拿來幹嘛用的
07/20 00:29, 1F

07/20 00:30, , 2F
這程式是在做什麼啊? XD
07/20 00:30, 2F

07/20 01:26, , 3F
看來來是判斷輸入的字串是不是由2個字元以上組合而成的
07/20 01:26, 3F

07/20 01:28, , 4F
且只看第2個字元其ASCII值是不是比m小。如果第i個字串符
07/20 01:28, 4F

07/20 01:29, , 5F
合條件,印出該字串的第i個字元的ascii值
07/20 01:29, 5F

07/20 01:29, , 6F
這到底是在檢查什麼鬼啊XD
07/20 01:29, 6F

07/20 07:17, , 7F
謝謝大大們!!小弟已了^^
07/20 07:17, 7F

07/20 13:26, , 8F
那ok應該是不用break的替代寫法吧
07/20 13:26, 8F

07/20 13:27, , 9F
for中的範圍條件和ok要同時成立,不然就會中斷,因此
07/20 13:27, 9F

07/20 13:27, , 10F
把ok設為假就會中斷for 有了break其實不必用到這手
07/20 13:27, 10F
文章代碼(AID): #1AOqONrF (C_and_CPP)