Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (60 points) Write a program to extract Web addresses starting with www. and e

ID: 3672881 • Letter: 1

Question

1. (60 points) Write a program to extract Web addresses starting with www. and ending with .edu. The program displays Web address contained in the input entered by the user. If the input does not contain a web address that starts with www. and ends
with .edu, the program should display a message that indicates such a web address cannot be found.

Your program should include the following function:

void extract(char *s1, char *s2);
The function expects s1 to point to a string containing the input as a string and stores

the output to the string pointed by s2.

1) Name your program extract.c.
2) Assume input is no longer than 1000 characters. Assume the input contains no

more than one qualifying web address.

3) The extract function should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the function.

4) To read a line of text, use the read_line function (the pointer version) in the lecture notes.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

void extract(char *s1, char *s2);

int main(){
char input[1000];
char output[1000];
int b=0;

while(!b){
system("cls");
printf("Welcome the Extract Web Addresses ");
  
printf("Enter the Web Addresses or 'Quit': ");
scanf("%s", input);
  
if (strstr(input,"Quit")!=NULL) {
break;
}

extract(input, output);
printf("%s",output);
}

system("pause");
return 0;
}

void extract(char *s1, char *s2){
if ((strstr(s1,"www.")!=NULL) && (strstr(s1,".edu")!=NULL)){
strcpy(s2, "www.");   
int posI = strspn(s1, "www.");
int posF = strspn(s1, ".edu");
int c=1;
int i;
for (i=posI; i<posF; i++){
s2 = (s1+i);
s2++;
c++;
}
strcpy(s2, ".edu");
  
}else
strcpy(s2, "Web address starting with www. and ending with .edu ");
}