Ah, works like a charm--thanks so much! Now, when I try to open the file, it doesn't quite work. I know I'm pointing to the right location because the file does open when, after all that code, I say modelfile=(string with the right file name), where that string is exactly the same as what I created (modelname.xx). Any idea what the problem is here? Code:
Code:
for (i = 0; i <= 90; i += 5) { //Loops through all inclinations.
if (i < 10) {
sprintf(inc, "0%d", i);
} else {
sprintf(inc, "%d", i);
}
modelfile = malloc(strlen(modelname) + strlen(inc) + strlen("Lightcurves\\") + 1);
sprintf(modelfile, "%s%s%s%s", "Lightcurves\\", modelname, inc, ".mag");
printf("%s\n", modelfile); //String 1
modelfile="Lightcurves\\modelB.00.mag";
printf("%s\n", modelfile); //String 2, appears exact same as String 1
model = fopen(modelfile, mode); //This opens the file properly with String 2 but NOT when I use string 1.
if (model == NULL) { //Error handling.
fprintf(stderr, "Can't open input file!\n");
system("pause");
exit(1);
} else {
printf("File opened successfully.\n");
}
system("pause");
free(modelfile);
} //Ends loop.