#include #include #include //checkmailaddress.c //---------------------------------------- // Function to check the character // is an alphabet or not int isChar(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); } //----------------------------------------- // Function to check the character // is an digit or not int isDigit(const char c) { return (c >= '0' && c <= '9'); } //----------------------------------------- // Function to check email id is valid or not int is_valid(char* email) { // Check the first character // is an alphabet or not if (!isChar(email[0])) { // If it's not an alphabet // email id is not valid return 0; } // Variable to store position // of At and Dot int At = -1, Dot = -1; int len; // Traverse over the email id // string to find position of // Dot and At len = strlen(email); // check mailadresse ob kleiner als 7 ist if (len<7) return 0; for (int i = 0; i < len; i++) { // If the character is '@' and the name is longer then 1 char if (email[i] == '@' && i > 0) { At = i; } // If character is '.' and the domain is min 2 chars long else if (email[i] == '.' && (len-2) > i ) { Dot = i;} } //If At and Dot are together with no char between if (At+1 == Dot) return 0; // If At or Dot is not present if (At == -1 || Dot == -1) return 0; // If Dot is present before At if (At > Dot) return 0; // If Dot is present at the end if (Dot >= (len-1)) return 1; } // ################################################# int main(int argc, char *argv[]) { if (argc != 2){ fprintf(stderr,"usage: %s emailaddress\n",argv[0]); exit (EXIT_FAILURE); } // Given string email char* email = argv[1]; // Function Call int ans = is_valid(email); // Print the result if (ans) { printf("%s : valid\n",email); } else { printf("%s : invalid\n",email);} return (EXIT_SUCCESS); }