title: Segmentation fault on loader for Sokoban game in C
body: <p>So I'm trying to write a code in C that would create an array of characters from a file looking like :</p>
  
  <pre><code>10 8
  ##########
  ######  ##
  # $  $  ##
  # #  .# ##
  #  . #.@ #
  ##$# *   #
  ##   #####
  ##########
  </code></pre>
  
  <p>But I'm stuck with a segmentation fault and I've been searching where it could come from unsuccessfully... I would really appreciate if someone could read my code and give me his/her feedback...
  Thanks in advance !</p>
  
  <pre><code>//We define a structure representing a map (for the Sokoban game)
      typedef struct map map;
      struct map{
          int width;
          int height;
          int x;
          int y;// x and y are the position of the player
          char* p_char; //p_char is pointing an array which will contain the elements of the map, the characters currently on the file above
      };
  
      //The function that reads the file and store the characters in an array
      char* ReadMap(const char const* filename)
      {
          FILE* p_file = fopen(filename, "r");
          char* p_array = NULL;
          if (p_file = NULL) {
              exit(EXIT_FAILURE);
          }
          else{   
              size_t size=1;
              while (getc(p_file)!=EOF) {
                  size++;
              }
              p_array=(char*)malloc(sizeof(char)*size);
              fseek(p_file,0,SEEK_SET);
              for(size_t i=3; i&lt;size-1; i++) {
                  p_array[i]=(char)getc(p_file);//i=3 cause we don't want the 2 first int, representing the size of the array
              }
              p_array[size-1]='\0';
              fclose(p_file);
          }
          return p_array;
      }
  
      int main(int argc, char *argv[]){
          if (argc != 2) {
              fprintf(stderr, "You must provide a file name!\n");
              exit(EXIT_FAILURE);
          }
          //We define a map structure
          map map_loaded; 
          FILE *p_file1 = NULL;
          p_file1=fopen(argv[1],"r");
          if (p_file1==NULL) {
              fprintf(stderr, "Cannot read file %s!\n", argv[1]);
              exit(EXIT_FAILURE);
          }
          //we're trying to recover width and height, two int at the beginnning of the file
          int width=0;
              map_loaded.width=width;
          int height=0;
              map_loaded.height=height;
          int fscanf_result=0;
              fscanf_result=fscanf(p_file1, "%d %d\n", &amp;width, &amp;height);
          char* p_char=NULL;
          map_loaded.p_char=p_char;
          p_char=ReadMap(argv[1]);
          if (p_char != NULL) {
              printf("%s\n", p_char);
              free(p_char);
          }
      }
  </code></pre>