写了个简单的文件读入并打印的程序,为什么会把最后一行多打印了一遍呢?
#include <stdio.h>#include <stdlib.h>struct stock{ char name[20]; int price;};int main(){ FILE *file; file = fopen("./stockInfo.txt", "r"); if(file == NULL) { printf("open file failed!\n"); exit(-1); } struct stock buffer; while(!feof(file)) { fscanf(file, "%s %d", buffer.name, &buffer.price); printf("%s %d", buffer.name, buffer.price); } return 0;}