Guest User

Untitled

a guest
Apr 25th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct Email {
  6. char * name;
  7. char * domain;
  8. } email_list[10];
  9.  
  10. char aaa[10];
  11.  
  12. int main(){
  13.  
  14. char buf[1024];
  15. fgets(buf,1024,stdin);
  16.  
  17.  
  18. int e_idx=0;
  19. char * res = strtok(buf,"@");
  20. while (1){
  21. if (res == 0){
  22. break;
  23. }
  24. printf("name %s\n",res);
  25. email_list[e_idx].name = malloc(strlen(res)+1);
  26.  
  27. strcpy(email_list[e_idx].name,res);
  28. res = strtok(NULL,";");
  29. if (res == 0){
  30. break;
  31. }
  32. printf("domain %s\n",res);
  33. if (e_idx !=3){
  34. email_list[e_idx].domain = malloc(strlen(res)+1);
  35. }
  36. else{
  37. email_list[e_idx].domain = malloc(16);
  38. }
  39. strcpy(email_list[e_idx].domain,res);
  40. e_idx++;
  41. if (e_idx==10)
  42. break;
  43. res = strtok(NULL,"@");
  44. }
  45. printf("Parsed %d emails\n",e_idx);
  46. return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment