title: Printing to file from global array of chars in c
body: <p>I am having a problem while trying to print to txt file from global array of char*.</p>
  
  <p>My array is declared as </p>
  
  <pre><code>char* codes[256];
  </code></pre>
  
  <p>also i have a function that construct a string and returns it to after which that value is placed into this global array</p>
  
  <pre><code>char* printArr(int arr[], int n)
  {
  
      char* code = (char *) malloc(sizeof(char) * (n+1));
  
      int i;
      for (i = 0; i &lt; n; ++i)
      {
          code[i] = arr[i] + '0';
      }
      code[n] = '\0';
  
      return code;
  }
  </code></pre>
  
  <p>after which I just simply place that value into that global array. After that I am trying to print that array values into a txt file like this : </p>
  
  <pre><code>void PrintToFile(char* outputFileName)
  {
  
     FILE* f = fopen(outputFileName, "w+");
  
     int i;
  
     for (i = 0; i &lt; 256; ++i)
     {
          //printf("%s\n", codes[i]);
          fprintf(f, "%s\n", codes[i]);
     }
  
     fclose(f);
  }
  </code></pre>
  
  <p>But for some reason my txt file turns out blank.
  Also without opened stream when I try to print to stdout i get those values but with both printf and fprintf I don't get anything out either on stdout or in txt file.</p>
  
  <p>Thanks in advance!</p>