I told it to print out the choice, and it does say a if you put a in, but it still says invalid choice. Not sure what ive done wrong
Code:
#include <stdio.h>
void addemail();
main()
{
int choice;
printf("Email whitelist");
printf("(a) to add email, (c) to check email against list, (e) to exit.\n");
printf("Choice: ");
scanf("%c",&choice);
printf("%c",choice);
switch (choice)
{
case 'a':
addemail();
break;
case 'c':
/* checkemail(); */
break;
case 'e':
break;
default:
printf("Invalid Choice.");
break;
}
}
void addemail()
{
char buf[40];
FILE *fp;
printf("Enter email: ");
fgets(buf, sizeof(buf), stdin);
fp = fopen("emails","a+");
fputs(buf,fp);
fclose(fp);
printf("\nEmail address %s added.",buf);
}