Cooler_

e-mail parser

Jun 26th, 2012
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. /*
  2. just another simple e-mail parse
  3. author: Cooler_
  4. contact: c00f3r [at] gmail [dot] com
  5.  
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. // return reverse string
  12. char *strrev(char *str);
  13.  
  14. int
  15. main()
  16. {
  17.  char *host="@gmail.com",*domain;
  18.  static char *s="lol blah [email protected]  blablablabla [email protected] bha bla [email protected] a aas  blah blah";
  19.  char *words=(char *)malloc(sizeof(char)*1024);
  20.  char *email=(char *)malloc(sizeof(char)*1024);
  21.  int x=0,z=0;
  22.  
  23.   domain=strdup(host);
  24.   domain=strrev(domain);
  25.  
  26.   do{
  27.    if(*s==' ')
  28.    {
  29.     words=strrev(words);
  30.  
  31. // compare end word to reverse string of host
  32.     while( *(domain+z)==*(words+z))
  33.      z++;
  34.    
  35.     if(z==strlen(domain))
  36.     {
  37.      email=strrev(words);
  38.      puts(email);
  39.     }
  40.  
  41.     memset(words,0,strlen(words));
  42.     words=strdup(" ");
  43.    
  44.     x=0;
  45.     z=0;
  46.    } else
  47.     *(words+x)=*s,x++;
  48.  
  49.    s++;
  50.   }while(*s != '\0');
  51.  
  52.  free(email);
  53.  free(domain);
  54.  free(words);
  55.  
  56.  return 0;
  57. }
  58.  
  59.  
  60. // return reverse string
  61. char
  62. *strrev(char *str)
  63. {
  64.  char *p1, *p2;
  65.  memset(str,0,0);
  66.  
  67.  if(! str || ! *str)
  68.   return str;
  69.  for(p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
  70.  {
  71.   *p1 ^= *p2;
  72.   *p2 ^= *p1;
  73.   *p1 ^= *p2;
  74.  }
  75.  return str;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment