I try to check how many @
there are in the string which I input. The problem is that I printf “c” once I “int c=0”, but “c” is a random integer in the output. How can I check if there is only one @
in the email address that I input?
typedef struct The_users {
char id[20];
char pwd[20];
char name[20];
char email[20];
} users;
//register system
void registers() {
users a, b;
FILE* fp;
char temp[20];
int count = 0;
if (fp = fopen("users.txt", "r") == NULL) {
fp = fopen("users.txt", "w");
fclose(fp);
}
fp = fopen("users.txt", "r");
fread(&b, sizeof(struct The_users), 1, fp);
while (1) {
printf("Please enter your email:\n");
gets(a.email);
int c = 0;
for (int i = 0; i < 20; i++) {
if (a.email[i] == "@") {
c++;
}
}
if (c == 1) {
break;
} else {
printf("----------------------------------------------\n");
printf("Not a correct email address! Please try again!\n");
printf("----------------------------------------------\n");
}
}
}