Computing Staff
  • 0

Writing An Array Of Numbers In A File In C.

  • 0

hi
i want to write an array of numbers (for example from 0 to 14) in a file
the source is something like that:
FILE *fp;
fp=fopen(“output.txt”,”w”);
for(int i=0;i<15;i++)
{a[i]=i;

fprintf(fp,”%f\n”,a[i]);
}
fclose(fp);
no output is printed.can anybody say what is the problem?

when i open the text file the output is there.
But it is not appearing in the output page when i run the program.
the function of fprintf statement is suppose to print output in both. is’nt it ?

Share

2 Answers

  1. Read…

    http://php.net/manual/en/function.f…

    try…

    FILE *fp;
    fp=fopen("output.txt","w+");
    for(int i=0;i<15;i++)
      {a[i]=i;
      fprintf(fp,"%f\n",a[i]);
      }
    fclose(fp);
    

    • 0
  2. fprintf: Writes to the specified stream a sequence of data formatted as the format argument specifies.
    No, it does not.

    • 0