Mega Code Archive

 
Categories / C / Development
 

Print e-mail addresses found in text

#include <stdio.h> #include <ctype.h> #include <string.h> int main(void) { char line[1024]; char address[256]; char *ptr1 = NULL; char *ptr2 = NULL; while((fgets(line, 1024, stdin)) != NULL) { if(strchr(line, '@') != NULL && strchr(line, '.') != NULL) { for(ptr1 = line, ptr2 = address; *ptr1; ptr1++) { if(isalpha(*ptr1) || isdigit(*ptr1) || strchr(".-_@", *ptr1) != NULL) *ptr2++ = *ptr1; else { *ptr2 = '\0'; if(strlen(address) >= 6 && strchr(address, '@') != NULL && strchr(address, '.') != NULL) printf("%s\n", address); ptr2 = address; } /* else */ } /* for */ } /* if */ } /* while */ return 0; }