My program handles/creates different type of files: projects, materials...
When a new project is created I use this code:
void
new_project(void)
{
char file_name[8];
FILE *output;
printf("Write the name of the new project \n");
scanf("%s", file_name);
output = fopen(file_name, "w");
printf("Please enter the characteristics of the new project \n");
printf("All the values are to be entered in meters, except the weight");
printf("\nwhich is in kilograms");
printf("\nLOA: ");
scanf("%lf", &LOA);
fprintf(output, "%.2f\n", LOA);
printf("\nI: ");
scanf("%lf", &I);
fprintf(output, "%.2f\n", I);
printf("\nJ: ");
scanf("%lf", &J);
fprintf(output, "%.2f\n", J);
printf("\nP: ");
scanf("%lf", &P);
fprintf(output, "%.2f\n", P);
printf("\nE: ");
scanf("%lf", &E);
fprintf(output, "%.2f\n", E);
printf("\nDisplacement (in kilograms): ");
scanf("%lf", &D);
fprintf(output, "%.2f\n", D);
printf("\nGM: ");
scanf("%lf", &GM);
fprintf(output, "%.2f\n", GM);
printf("\nH1: ");
scanf("%lf", &H1);
fprintf(output, "%.2f\n", H1);
printf("\nH2: ");
scanf("%lf", &H2);
fprintf(output, "%.2f\n", H2);
printf("\nH3: ");
scanf("%lf", &H3);
fprintf(output, "%.2f\n", H3); printf("\nS1: ");
scanf("%lf", &S1);
fprintf(output, "%.2f\n", S1);
printf("\nS2: ");
scanf("%lf", &S2);
fprintf(output, "%.2f\n", S2);
printf("\nS3: ");
scanf("%lf", &S3);
fprintf(output, "%.2f\n", S3);
fclose(output);
printf("\n\n Press any key to continue");
getch();
MENU();
}
But I would like to save the file with the extension .pro (for example). And when I create a new materials library I'd use the extension .mat.
This way, when the user asks for a list of all the existing projects, I'd look for all the files with the proper extension (I don't know how yet).
I've done a search and I saw that you guys suggest to use functions like:
sprintf strcpy strcat
But I don't really know how to apply them. I've looked through the help from the compiler (Borland Turbo C++ 3.0), and I didn't get anything clear.
Any help guys?