26.04.2013, 09:10
Haya!
I'm doing (re-writing) code for my tutor in College in UK, and I'm stuck about going back to the top of function if user press 'N' key, which means 'NO'.
Well, I know I should start a loop (using do & while iteration) and check in while, if my answer is 'N', use a break; statement and it should go back to the top. But it's not working. Probably I'm doing something wrong (not probably), but I need your help with it.
Here's the code:
I did read about going back to the top of the function on the internet, and it says, that I should call function name again. But I'm almost sure about break, so.. anybody?
edit://
Lol, I made a mistake with while at the end, here:
should be 'Y'. Nevermind! My mistake and stupidity.
I'm doing (re-writing) code for my tutor in College in UK, and I'm stuck about going back to the top of function if user press 'N' key, which means 'NO'.
Well, I know I should start a loop (using do & while iteration) and check in while, if my answer is 'N', use a break; statement and it should go back to the top. But it's not working. Probably I'm doing something wrong (not probably), but I need your help with it.
Here's the code:
Код:
int PromptUserForFilePaths(void)
{
// Local variables.
int count = 0;
char answer;
do
{
while(count != 1)
{
switch(count)
{
// Prompt for BATTING team file path.
case 0:
{
printf("Please enter BATTING team file location below:\n(format: Disk:\\Folder\\FileName)\n");
scanf("%s", file_path);
strcpy(batt_path, file_path);
break;
}
// Prompt for FIELDING team file path.
case 1:
{
printf("Please enter FIELDING team file location below:\n(format: Disk:\\Folder\\FileName)\n");
scanf("%s", file_path);
strcpy(batt_path, file_path);
break;
}
}
count += 1;
}
// Open each file for reading binary.
team_file = fopen(file_path, "rb");
// If file doesn't exists in the given location.
if(!team_file)
{
// Close file from reading.
fclose(team_file);
// Prompt user to create file in the given location.
printf("That file doesn't exists!\nCreate a new file in that location? (Y/N)");
answer = toupper(getch());
// Check, which option user chosen from prompt above.
switch(answer)
{
case 'Y':
{
team_file = fopen(file_path, "wb");
printf("Creating file. . .\nFile created successfully! Press any key to continue. . .");
getch();
}
case 'N':
{
system("PAUSE");
break;
}
}
}
}
while(answer != 'N');
return 0;
}
edit://
Lol, I made a mistake with while at the end, here:
Код:
while(answer != 'N');


hope it worked and good work.
