#include<stdio.h>
#include<stdlib.h>
typedef struct Room {
int values[4][4];
int size;
} Room;
int createRoom(Room *pm, char *mazefilename)
{
FILE *input;
FILE *output;
pm = (Room *)malloc(sizeof(Room *));
input = fopen(mazefilename, "r");
int a = 0;
int i = 0, j = 0;
int count;
char line[6];
fscanf(input, "%s", line);
while (!feof(input)) {
printf("Line is %s\n", line);
for (i = 0; i < 4; i++) {
int c = line[i] - '0';
pm->values[a][i] = c;
}
a++;
fscanf(input, "%s", line);
}
fclose(input);
return a;
}
This is giving me segmentation fault-
Line is 1001
Line is 1001
Line is 1101
Segmentation fault (core dumped)
Why is it giving me segmentation fault.If I just print the lines instead of pm->values[a][i]=c;
,it gives me the correct output.So I think something is wrong with this line-pm->values[a][i]=c;
My input file is-
1001
1001
1101
1109