Hi. I wrote a program that should make a file of pseudo random numbers. It should have a length of 1MB, because n=1'000'000.
The program works, but the resulting file have actually length of 1'003'904. Why doesn't the file have a length of 1'000'000 exactly?
Here is the source code:
Code:
/* this program is a pseudo random generator using function rand() */
#include<stdio.h>
#include<math.h>
main()
{
FILE *f1;
long int n,i;
int z;
printf("Processing..\n\n");
f1=fopen("output.out","w"); /*Open the file Input*/
n=1000000;
for(i=1;i<=n;i++){
z=rand() % 256;
putc(z,f1); /*write a character to input*/
}
fclose(f1); /*close the file input*/
printf("Done.");
getch();
}
Thank you for help.