Cooler_

parse test

Jun 26th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 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.  static char *domain="@gmail.com";
  18.  static char *s="lol blah 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=strrev(domain);
  24.  
  25. // separa uma palavra por linha
  26.   do{
  27.    if(*s==' ')
  28.    {
  29.     words=strrev(words);
  30.     *(words+x)='\n';
  31.     while( *(domain+z)==*(words+z) && z!=strlen(domain))
  32.      z++;
  33.     if(z==strlen(domain))
  34.      email=strrev(words);
  35.  
  36.     memset(words,1,x);
  37.     x=0;
  38.     z=0;
  39.    } else
  40.     *(words+x)=*s;
  41.    x++;
  42.    s++;
  43.   }while(*s != '\0');
  44.  
  45.  
  46.  puts(email);
  47.  
  48.  free(words);
  49.  free(email);
  50.  
  51.  return 0;
  52. }
  53.  
  54.  
  55. // return reverse string
  56. char
  57. *strrev(char *str)
  58. {
  59.  char *p1, *p2;
  60.  
  61.  if(! str || ! *str)
  62.   return str;
  63.  for(p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
  64.  {
  65.   *p1 ^= *p2;
  66.   *p2 ^= *p1;
  67.   *p1 ^= *p2;
  68.  }
  69.  return str;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment