Guest User

Untitled

a guest
Feb 19th, 2018
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1.  
  2. 1 #include <stdio.h>
  3. 2 #include <stdlib.h>
  4. 3 #include <string.h>
  5. 4
  6. 5
  7. 6 void print_validity(char * address, terminators, length);
  8. 7
  9. 8 void print_validity(char * address, terminators, length)
  10. 9 {
  11. 10 printf("The string %s is ", address);
  12. 11 if (!isValidEmailAddress(address, terminators, length) printf("not "));
  13. 12
  14. 13
  15. 14 printf("a valid email address\n");
  16. 15 }
  17. 16
  18. 17
  19. 18 int main()
  20. 19 {
  21. 20 const int length = 5;
  22. 21 char * terminators[length];
  23. 22 char * address1, address2;
  24. 23
  25. 24 terminators[0] = "com";
  26. 25 terminators[1] = "net";
  27. 26 terminators[2] = "edu";
  28. 27 terminators[3] = "ie";
  29. 28 terminators[4] = "tv";
  30. 29
  31. 30 address1 = "santa.claus@north.pole.com";
  32. 31 address2 = "I.am@fish";
  33. 32
  34. 33 print_validity(address1, terminators, length);
  35. 34 print_validity(address2, terminators, length);
  36. 35
  37. 36 return 0;
  38. 37 }
  39. 38
  40. 39
  41. 40
  42. 41
  43. 42
  44. 43 int isValidEmailAdress(address, terminators, length){
  45. 44
  46. 45 while(str[i]!='@'){
  47.  
  48. 46
  49. 47 if(isdigit(str[i])!=0&&isalpha(str[i])!=0&&str[i]!= '.'&&str[i]!="_"){
  50. 48 return 0;
  51. 49 }
  52. 50
  53. 51
  54. 52
  55. 53 }
  56. 54
  57. 55
  58. 56
  59. 57 int tokenise(char str[], int start, char result[]){
  60. 58 int i=start;
  61. 59 int j=0;
  62. 60
  63. 61 while(str[i]!='@'){
  64. 62
  65. 63 if(isdigit(str[i])!=0&&isalpha(str[i])!=0&&str[i]!='.'&&str[i]!="_"){
  66. 64 return 0;
  67. 65 }
  68. 66
  69. 67
  70. 68 else{
  71. 69 return 1;
  72. 70 }
  73. 71
  74. 72
  75. 73 while(str[i]!=' '){
  76. 74
  77. 75
  78. 76
  79. 77 if(str[i]=='\0'){
  80. 78 result[j]='\0';
  81. 79 return -1;
  82. 80 }
  83. 81 i++;
  84. 82
  85. 83 }
  86. 84 result[j]='\0';
  87. 85 return i;
  88. 86 }
  89. 87 }
  90. 88
Add Comment
Please, Sign In to add comment