Just for the record: I spent a while already checking similar questions and trying their proposed answers without success
I am facing a "Segmentation fault" error in runtime with the following C code:
#include <stdio.h>
#include <stdlib.h>
#define ROW_NUM 8
#define COL_NUM 7
typedef struct {
int matrix[ROW_NUM][COL_NUM];
} screen_type;
typedef struct {
screen_type *p_screen;
} snake_type;
void fillSnake(snake_type *p_snake);
int main(void) {
snake_type snake;
fillSnake(&snake);
return 0;
}
void fillSnake(snake_type *p_snake) {
fillWithPointer((screen_type*)p_snake->p_screen);
}
void fillWithPointer(screen_type *p_screen) { //segmentation fault in this method
for (int col = 0; col < COL_NUM; col++) {
for (int row = 0; row < ROW_NUM; row++) {
p_screen->matrix[row][col] = 0;
}
}
}
The problem is while filling the array with the method fillWithPointer
.
Any hints will be more than welcome.