title: Saving and printing a matrix from another file in a function
body: <p>This program should call a function that opens an external file and browse it counting the rows of it, then it creates a pointer to a matrix and browses again the file but now saving its data on the matrix and returns that matrix, after that it will print the matrix.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  int tam;
  float **carga_archivo(char *nombre_archivo);
  int main()
  {
      int i,j;
      char *nombre_archivo="Agua_Vapor.txt";
      float **agua_vapor=carga_archivo(nombre_archivo);
      for (i = 0; i &lt; 6; i++)
      {
          for (j = 0; i &lt; tam; i++)
              printf("%f   ", agua_vapor[i][j]);
          printf("\n");
      }
      return 0;
  }
  float **carga_archivo(char *nombre_archivo)
  {
      int i=0;
      float P[300][6];
      FILE *archivo;
      archivo=fopen(nombre_archivo,"r");
      while(!feof(archivo))
      {
          i++;
          fscanf(archivo,"%f\t%f\t%f\t%f\t%f\t%f\n",
                    &amp;P[0][i],&amp;P[1][i],&amp;P[2][i],&amp;P[3][i],&amp;P[4][i],&amp;P[5][i]);
              //This part is just so the program can read the file line per line,
              //else it would count character per character, doesn't really do anything
              //(I didn't know the command or condition to do it other way
      }
      tam=i;
      printf("%i",tam);
      int filas = 6;
      int columnas = tam;
      float **M = (float **)malloc(filas*sizeof(float*));
      for (i=0;i&lt;filas;i++)
          M[i] = (float*)malloc(columnas*sizeof(float));
      for (i = 0; i &lt; columnas; ++i)
          fscanf(archivo,"%f\t%f\t%f\t%f\t%f\t%f\n",&amp;M[0][i],&amp;M[1][i],
                                         &amp;M[2][i],&amp;M[3][i],&amp;M[4][i],&amp;M[5][i]);
      fclose (archivo);
      return M;
  }
  </code></pre>
  
  <p>The problem here is that when the matrix should be printed the program crashes, I know the program does saves the data, since when I print it directly inside the function I does prints, so I think it might be ether the way I'm declaring the matrix or the function or the way I'm calling to the function.</p>
  
  <p><strong>Edit</strong>: The content of the file it calls is just a data set separated by tabulations.</p>
  
  <blockquote>
    <p>0.06  36.16   23.739  2425.0  2567.4  8.3304</p>
    
    <p>0.06  80.00   27.132  2487.3  2650.1  8.5804  </p>
    
    <p>0.06  120.00  30.219  2544.7  2726.0  8.7840</p>
    
    <p>0.06  160.00  33.302  2602.7  2802.5  8.9693</p>
    
    <p>0.06  200.00  36.383  2661.4  2879.7  9.1398</p>
    
    <p>0.06  240.00  39.462  2721.0  2957.8  9.2982</p>
    
    <p>0.06  280.00  42.540  2781.5  3036.8  9.4464</p>
    
    <p>0.06  320.00  45.618  2843.0  3116.7  9.5859</p>
    
    <p>0.06  360.00  48.696  2905.5  3197.7  9.7180</p>
    
    <p>0.06  400.00  51.774  2969.0  3279.6  9.8435</p>
  </blockquote>
  
  <p>(you can't note the tabulations but they are there)</p>
  
  <p>Any correction is welcome.</p>