Using flush on stdin is very bad because it has undefined results. If you're interested in doing it a different way, it's a little messier but it doesn't rely on undefined behavior:
Code:
.
.
.
char choice [2]; /* Second slot is for '\0' */
int choice_size = sizeof(choice) / sizeof(choice[0]);
.
.
.
printf("\nChoice: ");
while( fgets(choice, choice_size + 1, stdin) )
{
int choice_int = atoi(choice);
switch(choice_int)
{
case 1: printf ("\nExam record has been created successfully.\n" ); break;
case 2: printf ("\nStudents record has been created successfully.\n" ); break;
case 9: printf ("\nExiting...\n"); break;
default: printf("Invalid choice!\n"); break;
}
if(choice_int == 9) { break; }
printf("\nChoice: ");
}
return 0;
.
.
.