全部。
在阅读了分段错误之后,我仍然无法弄清楚这个错误来自哪里。我知道它来自这个特定的功能;我的驱动程序中的其他所有内容都可以正常工作。
值得注意的是,所有样式都是枚举数据类型 StyleT。
被调用的函数:
openList(&list, "List.txt");
函数定义:
void openList(VehicleListT *list, char *infilename)
{
FILE *infile;
int i = 0;
char styleString[20];
newList(list);
if((infile = fopen(infilename, "r")) == NULL)
{
fprintf(stderr, "ERROR: Cannot open source file!\n");
exit(1);
}
fscanf(infile, "%s\n", list->vehicles[i].vin);
while(!feof(infile))
{
fscanf(infile, "%i\n", list->vehicles[i].year);
fscanf(infile, "%lf\n", list->vehicles[i].price);
fscanf(infile, "%s\n", list->vehicles[i].make);
fscanf(infile, "%s\n", styleString);
if((strcmp(styleString, "TWO_DOOR")) == 0)
{
list->vehicles[i].style = TWO_DOOR;
}
if((strcmp(styleString, "FOUR_DOOR")) == 0)
{
list->vehicles[i].style = FOUR_DOOR;
}
if((strcmp(styleString, "CONVERTIBLE")) == 0)
{
list->vehicles[i].style = CONVERTIBLE;
}
if((strcmp(styleString, "TRUCK")) == 0)
{
list->vehicles[i].style = TRUCK;
}
if((strcmp(styleString, "SUV")) == 0)
{
list->vehicles[i].style = SUV;
}
fscanf(infile, "%s\n", list->vehicles[i].color);
fscanf(infile, "%s\n", list->vehicles[i].vin);
i++;
list->count++;
}
fclose(infile);
return;
}