Hi guys,
I've been searching this forum and the FAQ for a solution for this problem but I can't find anything that works. Either I'm not applying it in the right way, or the solution is simply not on the forum yet.
Hope you can help me out. I call a filecopy function by using a switch menu. Now when Im finished copying the file it returns to the switch menu. Problem is that when it comes back to the switch menu, it automatically activates the default option (which I defined as closing the application). Now after reading here and there I think the input buffer is not yet empty when I get back to the menu, though I have no idea how to correct this. I've tried fflush but that didn't change anything. Also I've tried using fgets() instead of scanf() in my file copy function though then my program isn't able to open the filename I enter.
Hope that's clear enough, here are the code snippets:
The file copy function:
Code:
int analyse_data(void)
{
FILE *fpin, *fpout;
char flin[256],flout[256];
int ih;
clrscr();
puts(program_title);
puts(break_line);
puts(source_file);
// fgets(flin, sizeof(flin), stdin);
scanf("%s",flin);
// flin[strlen(flin)-1]='\0'; // delete \n
if((fpin = fopen(flin, "rb"))== NULL)
{
puts(source_file_error);
return 0;
}
puts(destination_file);
scanf("%s",flout);
// fgets(flout, sizeof(flout), stdin);
fpout=fopen(flout,"wb");
while((ih=fgetc(fpin))!=EOF)
{
fputc(ih,fpout);
putch(ih);
}
fclose(fpin);
fclose(fpout);
return 0;
}
The menu in main:
Code:
switch(menu_switch)
{
case 1:
exit_flag=FALSE;
test_procedure();
getch();
clrscr();
break;
case 2:
exit_flag=FALSE;
// puts("You chose 2");
analyse_data();
getch();
clrscr();
break;
case 3:
exit_flag=FALSE;
puts("You chose 3");
getch();
clrscr();
break;
case 4:
exit_flag=TRUE;
break;
default: exit_flag=TRUE;
}
}
while(exit_flag==FALSE);
You'll probably be able to see from the code that I'm not an expert programmer yet. Off topic tips are always welcome
Thanks a lot in advance, René