Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define STR_LEN 1000
- int read_line(char *str, int n) // Function that reads a string and saves it into an array
- {
- int ch, i = 0;
- while ((ch = getchar()) != '\n')
- { if (i < n)
- {
- *str++= ch;
- i++;
- }
- }
- *str = '\0';
- return i;
- }
- void extract(char *s1, char *s2)
- {
- char *p;
- char *p2;
- char *p3;
- int firstw = 0;
- int first_condition = 0;
- int second_condition = 0;
- for (p = s1; *p != '\0'; p++) // This loop checks if the address has www.
- {
- if((*p == 'w') && (*(p + 1) == 'w') && (*(p + 2) == 'w') && (*(p + 3) == '.'))
- {
- first_condition = 1;
- break;
- }else
- firstw++;
- }
- if (first_condition == 1) // This loop checks if the address has .edu
- {
- for(p2 = s1; *p2 != '\0'; p2++ )
- {
- if((*p2 == '.') && (*(p2 + 1) == 'e') && (*(p2 + 2) == 'd') && (*(p2 + 3) == 'u'))
- {
- second_condition = 1;
- break;
- }
- }
- }
- if ( (first_condition == 1) && (second_condition == 1)) // This loops disregards any imput after .edu
- {
- for (p3 = s1 + firstw; *p3 != '/'; p3++)
- {
- *s2 = *p3;
- if (*(p3 +1) != '/')
- s2++;
- }
- }
- else
- {
- printf("Sorry, something went wrong maybe the www. or the .edu formats are missing \n");
- }
- }
- int main (void)
- {
- char changed_address [STR_LEN];
- char address_str [STR_LEN];
- printf("Enter the website address: ");
- read_line(address_str, STR_LEN);
- extract(address_str, changed_address);
- printf("New address: %s\n", changed_address);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement