try:
Code:
#include <stdlib.h>
#include <stdio.h>
#define N 100
#define mode w
int j;
int i;
int main() {
FILE *fp;
char filename[] = "C:\\test.txt";
fp = fopen(filename, "wb");
for (i = 0; i < 100000; i++)
{
j = (int) rand();
if ( (fwrite(&j, // const void * ptr - Your array
sizeof(int), // size of each element in array
1, // number of elements in array
fp) != 1) // FILE * stream
{
fprintf(stderr, "Error writing to file.");
exit(1);
}
}
fclose(fp);
}
- Put code in code tags.
- Indicate which line the error belongs to. No one wants to count and we don't know if you have copied exactly.
- Indent your code.
- Do a tutorial.
- Check return value of fopen.
- Note that this writes values out in binary - not human readable.
Have Fun!