具體而言,我想介紹在開始時聲明的6區不同的汽車。該程序詢問我該車的哪個區域,如果輸入相同,我會繼續提供車輛的詳細信息,如果沒有,我想回到區讀。我的問題是,當我正確地讀了第一個地區,該計劃正常工作,並返回到區讀,但在第二個,不再工作。我將附上上面的代碼。我需要提到的是,這是我第一次使用「繼續」和「破發」聲明,我認爲這是主要問題。謝謝 !在do..while循環中繼續並打破語句錯誤
#include <stdio.h>
#include <string.h>
typedef struct record {
char name[15];
int year[4];
char serial[15];
char owner[24];
char plate[12];
};
int main() {
struct record rec[100];
char search[20];
int imax=0;
int i=0,j=0;
char n;
char* district[]= {"Rahova","Giulesti","Crangasi","Militari","Pantelimon","Ferentari"};
char district_input[20];
printf("\nEnter the cars: ");
do {
printf("\nCar's number %d -> Enter district: ",i+1);
scanf("%s",district_input);
for (;j<=5;j++) {
if(strcmp(district_input,district[j])==0){
printf("\t\t ->Name of the car: ");
scanf("%s",rec[i].name);
printf("\t\t ->Release year: ");
scanf("%d",rec[i].year);
printf("\t\t ->Serial number: ");
scanf("%s",rec[i].serial);
printf("\t\t ->Number plate: ");
scanf("%s",rec[i].plate);
printf("\t\t ->Last 3 owners: ");
scanf("%s",rec[i].owner);
printf("\nAdd more? [y/n]\t");
i++;
imax++;
break;
}
continue;
}
printf("\nAdd more? [y/n]\t");
} while ((n=getche()) != 'n');
}
的'continue'在'for'循環結束已沒有影響。不確定什麼不明確;閱讀C書中的兩條語句。 – Olaf