Below is the code that I'm having trouble with:
Code:
while(TRUE){
printf("Type in one of options below:\n1. Create File in root\n2. Navigate to Directory\n3. Quit\n");
printf(">>");
scanf("%d", &option);
fflush(stdin);
switch(option){
case 1:
createFile(disk,0);
break;
case 2:
navDir(disk, 0);
break;
case 3:
writeStructs(disk);
exit(1);
break;
default: break;
}
}
On the first run everything works, but after one of the functions returns back to a switch statement scanf doesn't wait for input and I get the output as below:
Code:
Type in one of options below:
1. Create File in root
2. Navigate to Directory
3. Quit
>>1
Enter file name and extension (file.doc): test.doc
Enter Content terminated by %>>this is a test%
Type in one of options below:
1. Create File in root
2. Navigate to Directory
3. Quit
>>Enter file name and extension (file.doc): Enter Content terminated by %>>
I tried flushing the buffer and using if statements instead of switch, but nothing seems to help. Any idea why this is happening?