title: How to save results of a function into text file in C
body: <p>This function print the length of words with '*' called histogram.How can I save results into text file? I tried but the program does not save the results.(no errors)</p>
  
  <pre><code>void histogram(FILE *myinput)
     {
     FILE *ptr;
     printf("\nsaving results...\n");
     ptr=fopen("results1.txt","wt");
  
     int j, n = 1, i = 0;
     size_t ln;
     char arr[100][10];
  
     while(n &gt; 0)
        {
        n = fscanf(myinput, "%s",arr[i]);
        i++;
        }
  
     n = i;
     for(i = 0; i &lt; n - 1; i++)
        {
        ln=strlen(arr[i]);
        fprintf(ptr,"%s \t",arr[i]);
        for(j=0;j&lt;ln;j++) 
           fprintf(ptr, "*");
  
        fprintf(ptr, "\n");
        }
  
     fclose(myinput);
     fclose(ptr);
     }
  </code></pre>