我正在爲學校編寫一個簡單的Mad Libs程序。我發佈的代碼通過搜索特定提示的數組迭代。一旦發現它使用提示問問題並記錄答案。然而,保留我的答案的數組省略了除第一個變量之外的每個單詞的首字母。這是我的代碼和數組輸出的副本。我知道這很客氣,但我正在學習。getline()省略了我的數組輸出的第一個字母。
char buffer[256];
int y = 0;
//iterates through array looking for answers
for(int i = 0;i <= 256;i++)
{
if(storyArray[i][0] == '<' && isalpha(storyArray[i][1]))
{
for(int x = 0; storyArray[i][x]; x++)
{
switch(storyArray[i][x]){
case '<':
cout << "\t";
x++;
putchar(toupper(storyArray[i][x]));
break;
case '>':
cout << ": ";
cin.ignore();
cin.getline(buffer,256);
strcpy(answerArray[y],buffer);
y++;
break;
case '_':
cout << " ";
break;
default:
cout << storyArray[i][x];
break;
}
}
}
}
輸出: Arrayitem1 rrayitem2
你想要加載什麼數據?你可以發佈一個樣本嗎? – jrd1 2013-03-19 01:55:15