emptying memory when coming from a function
I'm sure that there's been a thread with this question before (more or less), but I couldn't find it.
My program has a function that shows the values in a project. When I call this function (caracteristics) it runs perfectly, but as soon as it goes back to main, there's something wrong. A menu should be displayed (calling the function MENU()), but it displayed twice, and also, when I enter an option, it doesn't work correctly.
I thought that maybe I should have the memory emptied, when I finish the caracteristics() function, but I don't know how (this is actually what I've been looking for).
I attach the whole code (which compiles and runs), and I post the function caracteristics() as well (in case you don't want to download the whole thing, even it's quite small).
There it goes:
Code:
void
caracteristics(void)
{
double getval; // this variable GETs the VALues from the existing project
char file_name[PATH_MAX];
FILE *input;
clrscr();
strcpy (file_name, actual);
input = fopen(file_name, "r");
if (( input = fopen(file_name, "r+")) == NULL ) // check it for errors
{
printf("There was an error reading from the file!! \n");
printf("Press any key to continue ");
getch();
main();
}
printf("The caracteristics of the actual project are: \n");
fscanf(input, "%lf\n", &getval);
printf("1) LOA: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("2) I: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("3) J: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("4) P: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("5) E: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("6) Displacement: %.0f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("7) GM: %.3f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("8) H1: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("9) H2: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("10) H3: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("11) S1: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("12) S2: %.2f\n", getval);
fscanf(input, "%lf\n", &getval);
printf("13) S3: %.2f\n", getval);
fclose(input);
printf("\n\n Press any key to continue");
getch();
main();
}