I'm going to be outputting data to a bunch of different files with slightly different names.
The output filename should be of the form
/home/mmcevoy/3year/princcomp/ver2/tempnumber.dat
where number is an integer I'm pulling out of a list (and temp stays as a literal part of filename)
so, first I define the C-string
char dat[] = ".dat\"";
then I define my list of numbers as list
I set i to a specific integer and test by assigning
char tfilename[200];
sprintf(tfilename, "\"/home/mmcevoy/3year/princcomp/ver2/temp%d%s", list[i], dat);
when I do
printf("%s", tfilename);
the output reads
"/home/mmcevoy/3year/princcomp/ver2/temp1238.dat" (1238 is the right number)
but when I do
FILE *filet;
filet = fopen(tfilename, "w");
fclose(filet);
it compiles, but I get a segfault when I attempt to run
(using gcc compiler)
The output filename should be of the form
/home/mmcevoy/3year/princcomp/ver2/tempnumber.dat
where number is an integer I'm pulling out of a list (and temp stays as a literal part of filename)
so, first I define the C-string
char dat[] = ".dat\"";
then I define my list of numbers as list
I set i to a specific integer and test by assigning
char tfilename[200];
sprintf(tfilename, "\"/home/mmcevoy/3year/princcomp/ver2/temp%d%s", list[i], dat);
when I do
printf("%s", tfilename);
the output reads
"/home/mmcevoy/3year/princcomp/ver2/temp1238.dat" (1238 is the right number)
but when I do
FILE *filet;
filet = fopen(tfilename, "w");
fclose(filet);
it compiles, but I get a segfault when I attempt to run
(using gcc compiler)
Comment