我用的Turbo C(甚至沒有++),但它是很久很久以前......更嚴重的是,我認爲:
cnic
是一個大小爲13的字符數組(12 +終止null)
cnic2
應該是一個大小爲13的100個char數組的2D數組(它不是wha t寫在你的代碼中)
- 你想看看如果
cnic
C字符串已經在cnic2
,如果是你拒絕它,如果不是你添加它。
j
是cnic2
中下一個元素的索引,並且在主循環之前應明確設置爲0。
宣言:
char cnic2[100][13];
int found; /* should be bool found but unsure if Turbo C++ knows about that */
(你代碼被聲明大小100的13 C-Ctring的陣列)
測試環路(包括由OP的檢查和測試代碼):
/* should control size of nic before that processing - I ASSUME IT HAS BEEN DONE */
found = 0; /* should be found = false; and later use false and true instead of 0 and 1 */
for(i=0; i<j; i++) {
if (0 == strcmp(cnic, cnic2[i]) {
found = 1;
break;
}
}
if (found) {
cout<<"This Cnic has already casted the vote";
continue;
}
if (j == 99) {
count << "Too much Cnic already";
break;
}
strcpy(cnic2[j++], cnic);
/* Revised and Working Code
found = 0; /* should be found = false; and later use false and true instead of 0 and 1 */
for(i=0; i<j; i++) {
if (0 == strcmp(cnic, cnic2[i]))
{
found = 1;
break;
}
}
if (found) {
cout<<"This Cnic has already casted the vote";
continue;
}
if (j == 99) {
cout << "Too much Cnic already";
break;
}
strcpy(cnic2[j++], cnic);
*「我正在使用Turbo C++ 3.0編譯器」* ....哦沒有.... – CoryKramer
_ @ OP_請問您有什麼問題? –
該死的,那個編譯器比我老... –