在閱讀了分段錯誤之後,我仍然無法弄清楚這個人來自哪裏。我知道它來自這個特定的功能;我的驅動程序中的其他所有東西都可以工
值得注意的是,所有樣式都是枚舉數據類型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;
}
你怎麼知道你的車輛列表有足夠的內存來保存你正在閱讀的記錄數? – Jason 2013-04-25 02:22:32
.h文件中的最大限制設置爲20,在我的測試程序中,我只創建了4個條目並保存到文件「List.txt」,該文件是該函數打開的文件。 – Waterbagel 2013-04-25 02:23:26
通過一個調試器運行它,並找出該線路,它在哪裏seg故障... – 2013-04-25 02:27:27