Write a C program which reads the standard input and extract
Write a C program which reads the standard input and extract HTML-style tags from it. We consider that the HTML-style tags are all strings starting with character “less-than” (<) and end with the character “greater-than” (>). In case that there is a tag starting with ‘<’ but not finishing with ‘>’ at all, then print it all the way to the end of input. Each tag should start at a new line. Input The input is in a free textual form. Output The output consists of a list of tags in the order that they appear in text. Each tag should start on a new line. All content of a tag should be printed in the same way as it appears in input. If a tag is not finished, it should still be printed. The sample input and output below illustrate behaviour of the program.
Hint : The program should read input character by character and immediatelly produce output or not based on the context.
Hint : you can use getchar() and putchar() OR scanf() and prinf()
Sample Input:
Sample Output:
Solution
/* Program Code Begins */
#include <stdio.h>
int main( )
{
int ch,temp=0,temp2=0,i=0,j=0;
char ch2;
char ch5[1000];
printf(\"Enter input data :\ \");
while ( ( ch=getchar() ) != EOF ) // read characterwise input data until EOF,in Windows Ctrl+Z /unix Ctrl+D is equal to End of File character
{
ch5 [i]=ch; //write single input char into char array.
i++;
}
j=i;
i=0;
printf(\"Input Reading Stopped : Outpue Generating .......\");
while (j>=0 ) //read character wise data from array untilllast char.
{
ch2=ch5[i];
i++;
j--;
if(temp==0) //temperory varible to taken avoid other chars in input except html content
{
if(ch2==\'<\') //condtions to display html contents
{
temp=1;
printf(\"\ \");
}
}
if(temp==1) //temperory varible to taken avoid other chars in input except html content
{
if(ch2!=\'\ \')
printf(\"%c\",ch2);
if(ch2==\'>\') //condtions to display html contents
{
temp=0;
printf(\"\ \");
}
}
}
return 0;
}
Input :
Enter input data :
fkdsjlkfj<sldkjflksd
jflsdkflk><skdjflsdk<lksdjf>fklsd<adf>
^Z
Output :
Input Reading Stopped : Outpue Generating .......
<sldkjflksdjflsdkflk>
<skdjflsdk<lksdjf>
<adf>

