It seems like the data.out file has to be accessed at least once before I start calling other objects.
Not True.
It must be compiler dependent. Both work for me.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
FILE *outfile;
void report(void);
int main(int argc, char *argv[])
{
outfile = fopen(argv[2], "w");
printf("heyyy");
report();
return 0;
}
void report(void)
{
int nothing;
printf("Before fprintf\n");
fprintf(outfile, "Simulation results: \n\n");
nothing = getch();
}
And
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
FILE *outfile;
void report(void);
int main(int argc, char *argv[])
{
outfile = fopen(argv[2], "w");
printf("heyyy");
fprintf(outfile, "Hey World.\n");
report();
return 0;
}
void report(void)
{
int nothing;
printf("Before fprintf\n");
fprintf(outfile, "Simulation results: \n\n");
nothing = getch();
}
Ran from command line, c:/testing/test.exe 1 test.dat
It ran and created the file, saving both entries just fine.
Of course it did not work unless you run it from command/run line.
- Using Digital Mars free compiler. Found on Cnet/downlaods.