#include <stdio.h>
#include <string.h>
#define MAX_EMAIL_LENGTH 100
int main() {
char email[MAX_EMAIL_LENGTH];
// Step 1: Prompt user for email address
printf("Enter your email address: ");
// Step 2: Read email address from user
scanf("%s", email);
// Step 3: Validate email address format
int length = strlen(email);
int atIndex = -1, dotIndex = -1;
for (int i = 0; i < length; i++) {
if (email[i] == '@') {
atIndex = i;
} else if (email[i] == '.') {
dotIndex = i;
}
}
// Step 4: Check if '@' and '.' are present and in correct order
if (atIndex != -1 && dotIndex != -1 && atIndex < dotIndex) {
// Step 5: Display valid email address
printf("Valid email address: %s\n", email);
} else {
// Step 6: Display error message for invalid email address
printf("Invalid email address. Please enter a valid email.\n");
}
return 0;
}