I need to check to see if a path exists before saving a file to it.
My function has a "filespec" variable which contains the path and file name. Is there a way to check if the path exists?
Here is the function:
Code:
int saveprnfile(void)
{ // saves formatted output to a text file to be printed
FILE *fptr;
char *filename = "filename";
char filespec[79];
input(filename,79); // get path and file name
strcpy(filespec, lin); // copy path and file name to 'filespec'
lin[0] = '\0';
fptr = fopen(filespec, "a");
fprintf(fptr,"\t\t\t%s\n\n",filespec);
fprintf(fptr,"Header Design Suite\n");
fprintf(fptr,"Open Source Software\n\n\n");
fprintf(fptr,"\n\n======= Header Design Suite Input =======\n\n");
fprintf(fptr," Bore __________________ %2.3f\n", info.bore);
fprintf(fptr," Stroke ________________ %1.3f\n", info.stroke);
fprintf(fptr," Comp __________________ %2.1f to 1\n", info.compratio);
fprintf(fptr," RPM ___________________ %4.1f\n", info.maxrpm);
fprintf(fptr," Exhaust valve opens ___ %3.1f before BDC\n\n", info.exhaustopens);
fprintf(fptr,"==========================================\n\n");
fprintf(fptr,"======= Header Design Suite Output =======\n");
fprintf(fptr,"\n\nHeader: Four single primary tubes into common collector\n\n");
fprintf(fptr,"-------------------------------------------------------\n\n");
fprintf(fptr," Primary tube inside diameter: _ %1.3f\n\n", info.primarydia);
fprintf(fptr," Primary tube length: __________ %2.1f\n\n", info.primarylength);
fprintf(fptr," Collector diameter: ___________ %1.3f\n\n", info.collectordia);
fprintf(fptr," Collector length ______________ %2.3f\n\n\n", info.collectorlength);
fclose(fptr);
return(0);
}