I want this code to:
IF unsaved packets is greater or = 1,
then
print "There are unsaved packets"
"Would you like to saved them?"
"Type Y for Yes or N for No"
Get user input
IF User input = Y then function save
ELSE IF User input = N then exit
ELSE Return to menue
here is my current code, the problem is it won't take the input at all and if it does it doesn't use it to determine what happens after.
if(unsavedPackets >= 1)
{
puts("There are currently unsaved packets in the memory");
puts("\nWould you like to save them?");
puts("\nType Y for Yes or N for No");
getch(saveChoice);
printf("%c", saveChoice);
if(saveChoice == "Y")
{
puts("Saving records");
save(recordCount, records);
exit(1);
}
else if(saveChoice == "N")
{
exit(1);
}
else
{
printf("Returning to main menu");
}
}
break;
One problem is that
where you should write
Similarly for "N"
In the first case, you are comparing
char
withconst char *
where second is pointer, not a character.Your
break
statement will always be executed no matterif
condition is true or false.