我正在读一本书。尺寸为512*681的pgm文件。
我的调试器将分段错误指向
fscanf(image, "%d", (*M)[i][j]);
.我应该如何修复它?
我没有添加一些函数,例如
open_pgm
因为我相信他们一切都好。
输入
12
13
12
12
12
12
10
。。。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
void Store(int ***M, int lines, int columns, FILE *image)
{
for(int l = 0; l < lines; l++)
{
for(int c = 0; c < columns; c++)
{
fscanf(image, "%d", (*M)[l][c]);
}
}
}
int main(int argc, char *argv[])
{
FILE *image;
char *string;
int lines;
int columns;
string = malloc(18*sizeof(char));
open_pgm(string, argv, &image);
fscanf(image, "%d %d", &lines, &columns);
int **M;
allocMatrix(&M, lines, columns);
Store(&M, lines, columns, image);
printf("%d\n", M_lida[0][0]);
close(&imagem);
close(&texto);
return 0;
}