我想使用fgets用C语言读取pgm文件,但出现错误,我不知道是哪条指令引起的。
这是我的代码:
FILE* file = NULL;
char chaine[TAILLE_MAX] = "";
int elts[TAILLE_MAX];
image = fopen("test.txt", "r+");
if(image != NULL)
{
int i=0;
while (fgets(chaine, TAILLE_MAX, file) != NULL)
{
elts[i] = atoi(chaine);
printf("%d\n", i);
i++;
}
}
读取直到文件的最后一行。这是输出:
...
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
RUN FINISHED; Segmentation fault; core dumped; real time: 140ms; user: 0ms; system: 0ms
问题不是文件,但我认为这与fgets函数有关