title: writing the content of a matrix in a file in C
body: <p>I'm having some problem at writing a matrix in a file, and I can't realise why my code is not working. The code is the following:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  
  FILE*data, *temp;
  char *s;
  int ch,i,y,j;
  char n,m;
  char buffer[10];
  char field[10][10];
  int main()
  {
    i=0;
    data=fopen("data.txt", "r");
    while((ch = fgetc(data))!= EOF)
    {
      if(ch != '\n')
      {
        buffer[i] =ch;
        i++;
      }
  
    }
  
    for(y = 0; y&lt;i; y++)
    {
      printf("%c ", buffer[y]);
    }
  
    fclose(data);
    n=buffer[0];
    m=buffer[1];
    //char field[n][m];
    printf("\n n=%c m=%c\n",n,m);
    for(i=1; i&lt;=n; i++)
    {
      for(j=1; j&lt;=m; j++)
      {
        field[i][j]=0;
      }
    }
    field[buffer[3]][buffer[4]]='c';
    field[buffer[6]][buffer[7]]='e';
    for(i=buffer[9]; i&lt;=buffer[12]; i++)
    {
      for(j=buffer[10]; j&lt;=buffer[11]; j++)
      {
        field[i][j]='y';
      }
    }
    temp=fopen("temp.txt","w");
    for(i=1; i&lt;=n; i++)
    {
      for(j=1; j&lt;=m; j++)
      {
        printf("%d", field[i][j]);
        fprintf(temp,"%",field[i][j]);
        if(j==m)
        {
          fprintf(temp,"\n");
        }
      }
    }
    fclose(temp);
  
  
    return 0;
  }
  </code></pre>
  
  <p>Also, I've inserted some code so that the matrix gets printed in the console. There is a file called data.txt, which represents the input data, that contains something like:</p>
  
  <pre><code>56
  c11
  e16
  y4456
  </code></pre>
  
  <p>the first line gives the dimensions of the matrix, 5X6, the second says that on line 1,column1 in the matrix should be a character 'c', 3rd line says that on line 1, col. 4 should be 'e', and in the last line, there a given the coordinates of 2 corners inside the matrix: line4, col.4, and line 5, col.6. In this space, delimites by these corners, I need to have the character 'y'. on the other spaces of the matrix, I chose to put '0'. I want to write ths matrix in the file "temp.txt", but is not working:(. I kept trying, but useless. Please, give me a hint or something.
  Thank you in advance!</p>