I'm not sure if this question has been asked before but I couldn't find the exact issue so here it is.
At the beginning of the program I have a log in screen that will hide the entered password. It will then be compared against a user name and password from a txt file. For the sake of this question I just set the credentials in the main.
After hitting the enter to break the password entry it exits the do while and should then start the while and ask for the choice from the menu using a scanf. The program ignores the scanf and runs infinitively. The functions are declared above and I have included stdio.h, conio.h, stdlib.h, string.h. The code is as follows:
void main() {
int i, run = 0, choice, loc = 0;
node* top;
top = NULL;
login();
//While the run loop is 0 show the menu and take choice input
do {
printf("\n\tMenu\n");
printf("\n1 - Add survey");
printf("\n2 - Display all survey");
printf("\n3 - Display a survey");
printf("\n4 - update a survey");
printf("\n5 - delete a survey");
printf("\n6 - generate survey statistics");
printf("\n7 - Print to file");
printf("\n8 - Quit");
printf("\nPlease enter your choice:");
scanf("%d", &choice);
if (choice == 1) {
addSurvey(&top);
}// add a survey
else if (choice == 2) {
displaySurveys(top);
}//display all surveys
else if (choice == 3) {
printf("\nEnter the PPS: ");
scanf("%d", &loc);
diplaySurvey(top, loc);
}//display particular survey
else if (choice == 4) {
printf("\nEnter the PPS: ");
scanf("%d", &loc);
updateSurvey(top, loc);
}// update a survey
else if (choice == 5) {
printf("\nEnter the PPS: ");
scanf("%d", &loc);
deleteSurvey(&top, loc);
}// delete a survey
else if (choice == 6) {
generateStats(&top);
}// generate statistics
else if (choice == 7) {
printToFile(&top);
}//Print to file
else if (choice == 8) {
run = 1;
exit(0);
}//Quit
} while (run == 0);//while running
}//main
void login() {
int i, allGood = 1;
char letter, username[10], password[10], user[10] = "user", pass[10] = "pass";
//the login screen
do { // Do this while its not all good :(
printf("\nTo log in please enter your credentials: ");
printf("\nUsername: ");
scanf("%", username);
printf("Password: ");
//Take in a password from the user and replace the input with ****
for (i = 0; i < 10; i++) {
letter = getch();
//if the user hits the return key end password input
if (letter == '\r') {
password[i] = '\0';
printf("\nPress ENTER to continue!\n");
break;
}//if
//If the user enters backspace delete the last char
/*else if (letter == '\p') {
i--;
password[i - 1] = '\0';
}//else if*/
password[i] = letter;
printf("*");
}//for
if (!(strcmp(user, username) && strcmp(pass, password))) {
allGood = 0;
}//if the inputted credentials & the actual match set all good to 0
} while (allGood == 1);
fflush(stdin);
getch();
}//Login