为什么我的字符串在此循环?

时间:2014-03-17 14:51:17

标签: c while-loop

我在循环中检查carNo,所以我请求用户输入。 但字符串"输入carBrand和carPrice:"在控制台中循环。不明白为什么。

//manually fill records

filePtr = fopen("CARDATABASE.dat", "rb+");
printf("Enter car no: ");
scanf("%d", &blankEntry.carNo);

while (blankEntry.carNo!=0){

    printf("Enter carBrand and carPrice: \n");
    fscanf(stdin, "%d %s %f", &blankEntry.carNo, blankEntry.carBrand, &blankEntry.carPrice);
    fseek(filePtr, (blankEntry.carNo - 1)*sizeof(struct carData), SEEK_SET);
    fwrite(&blankEntry, sizeof(struct carData), 1, filePtr);        
    printf("Enter car no: ");
    scanf("%d",&blankEntry.carNo);

}

0 个答案:

没有答案