Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define STR_LEN 1000
  4.  
  5. int read_line(char *str, int n) // Function that reads a string and saves it into an array
  6. {
  7. int ch, i = 0;
  8. while ((ch = getchar()) != '\n')
  9. { if (i < n)
  10. {
  11. *str++= ch;
  12. i++;
  13. }
  14.  
  15. }
  16.  
  17. *str = '\0';
  18. return i;
  19. }
  20.  
  21. void extract(char *s1, char *s2)
  22. {
  23. char *p;
  24. char *p2;
  25. char *p3;
  26. int firstw = 0;
  27. int first_condition = 0;
  28. int second_condition = 0;
  29.  
  30. for (p = s1; *p != '\0'; p++) // This loop checks if the address has www.
  31. {
  32. if((*p == 'w') && (*(p + 1) == 'w') && (*(p + 2) == 'w') && (*(p + 3) == '.'))
  33. {
  34. first_condition = 1;
  35. break;
  36. }else
  37. firstw++;
  38. }
  39.  
  40. if (first_condition == 1) // This loop checks if the address has .edu
  41. {
  42. for(p2 = s1; *p2 != '\0'; p2++ )
  43. {
  44. if((*p2 == '.') && (*(p2 + 1) == 'e') && (*(p2 + 2) == 'd') && (*(p2 + 3) == 'u'))
  45. {
  46. second_condition = 1;
  47. break;
  48. }
  49. }
  50. }
  51.  
  52. if ( (first_condition == 1) && (second_condition == 1)) // This loops disregards any imput after .edu
  53. {
  54. for (p3 = s1 + firstw; *p3 != '/'; p3++)
  55. {
  56. *s2 = *p3;
  57. if (*(p3 +1) != '/')
  58. s2++;
  59. }
  60.  
  61. }
  62. else
  63. {
  64. printf("Sorry, something went wrong maybe the www. or the .edu formats are missing \n");
  65. }
  66. }
  67.  
  68. int main (void)
  69. {
  70. char changed_address [STR_LEN];
  71. char address_str [STR_LEN];
  72. printf("Enter the website address: ");
  73. read_line(address_str, STR_LEN);
  74. extract(address_str, changed_address);
  75. printf("New address: %s\n", changed_address);
  76. return 0;
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement