#include <stdio.h>
void parser(char *inp2)
{
int i = 0, i2 = 0;
int flag = 1;
while (*(inp2 + i2) != '\0')
{
if (*(inp2 + i2) == '<')
{
i=i2;
if (flag % 2 == 0)
{
*(inp2 + i - 1) = '0';
}
while (*(inp2 + i) != '>')
{
*(inp2 + i) = '0';
i++;
}
*(inp2 + i) = '0';
if (flag % 2 != 0)
{
*(inp2 + i + 1) = '0';
}
flag++;
}
i2++;
}
}
int main()
{
char inp[100];
int i2 = 0, i = 0;
printf("Enter HTML line to be parsed\n"); // delete it
scanf("%[^\n]s", &inp);
printf("\nYour input is: ");
while (inp[i] != '\0')
{
printf("%c", inp[i]);
i++;
}
printf("\n-------------------------\n\n");
parser(inp);
while (inp[i2] != '\0')
{
if (inp[i2] == '0')
{
i2++;
continue;
}
printf("%c", inp[i2]);
i2++;
}
return 0;
}
Logic- Instead of deleting the character from array I instead subsituted them with character '0' and then I traversed the modified input and asked the interpreter to skip to next iteration on finding '0'.😀
Comments
Post a Comment