| Current Path : /var/www/html/mmishra/nweb/ |
| Current File : /var/www/html/mmishra/nweb/jatin.c |
#include <stdio.h>
char buff[100000000];
int len = 0;
int start_tag(int x)
{
while(x >= 0 && buff[x] != '<'){
//printf("%c",buff[x--]);
x--;
}
return x;
}
int end_tag(int x)
{
int open = 1;
int close = 0;
while(x < len) {
if(buff[x] == '<') {
int check = 0;
while(x < len && buff[x] != '>') {
if(buff[x] == '<' && buff[x+1] == '/') {
check = 1;
}
x++;
}
if(check) {
close++;
}else{
open++;
}
if(open == close) {
return (x);
}
}
x++;
}
printf("someting worng happend :( \n");
while(1);
}
void del(int x, int y)
{
printf("Filtered tag: ");
for(; x <= y; x++) {
printf("%c",buff[x]);
buff[x] = ' ';
}
printf("\n");
}
void filter_tag(char str[],int len)
{
int i = 0;
while(i < len) {
//printf("%d \n",i);
if(buff[i] == str[0]) {
int j = i;
int k = 0;
int check = 0;
while(j < len && str[k] != '\0') {
if(str[k] != buff[j]) {
check = 1;
break;
}
j++;
k++;
}
if(!check) {
int start = start_tag(i);
int end = end_tag(j);
del(start,end);
}
}
i++;
}
}
int main()
{
FILE *f1,*f2;
char str[1000];
printf("search string\n");
scanf("%s",str);
f1 = fopen("index.html","r");
f2 = fopen("index.htm","w");
char c = getc(f1);
while(c != EOF) {
buff[len++] = c;
c = getc(f1);
}
filter_tag(str,len);
//printf("%s",buff);
fprintf(f2,"%s",buff);
fclose(f1);
fclose(f2);
return 0;
}