You are to process an html file called links.txt (create this file with the Samp
ID: 3567492 • Letter: Y
Question
You are to process an html file called links.txt (create this file with the Sample Input file
below) that contains html links in the following format:
<a href="web_address_here">Link Text</a>
Develop a C program that extracts the web address from html links and prints them on screen.
Assume that each html links appears on a separate line within the html file. Also print the length
of the longest web address.
Your program should call a function with the following prototype
void extract(char hyperlink[], char address[])
where
Explanation / Answer
void extract(char hyperlink[], char address[])
{
int i =0,z=0;
int found =0, start=0,end=0;
for ( i = 0; i < strlen(hyperlink); i++)
{
if (hyperlink[i] == '"' && found ==0)
{
start = i;
found =1;
}
if (found ==1 && hyperlink[i] == '"')
{
end = i;
}
}
for (i=start+1; i < end; i ++)
{
address[z] = hyperlink[i];
z++;
}
}
int main(int argc, const char * argv[])
{
char hyperlink[100];
char address[100];
printf("type the link: ");
scanf("%s", hyperlink);
extract(hyperlink, address);
printf("%s", address);
printf(" ");
printf("address length: %lu characters", strlen(address));
printf(" ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.