#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N sizeof(struct check)
struct check
{
char words[15];
struct check * next;
}*L,*r,*p,*s;
FILE *f;
char ch;
int main()
{
r=L=(struct check *)malloc(N);
void read();
void del();
void emt();
void del_word();
void print();
read();
del();
emt();
del_word();
print();
return 0;
}
void read()
{
if(!(f=fopen("1.txt","r")))
{
printf("文件打开错误\n");
exit(0);
}
while((ch=fgetc(f))!=EOF)
putchar(ch);
fclose(f);
printf("\n\n\n\n\n\n\n\n\n删除链接后的内容\n\n\n\n\n");
}
void del()
{
FILE *fp;
fp=fopen("2.txt","w");
int t=0;
if(!(f=fopen("1.txt","r")))
{
printf("文件打开错误\n");
exit(0);
}
while((ch=fgetc(f))!=EOF)
{
if(ch=='<')t=1;
if(ch=='>')t=0;
if(t);
else if(ch!='>')fputc(ch,fp);
}
fclose(fp);
fp=fopen("2.txt","r");
while((ch=fgetc(fp))!=EOF)
printf("%c",ch);
fclose(f);
fclose(fp);
}
void emt()
{
int i=0,t=0,word=0;
if(!(f=fopen("2.txt","r")))
{
printf("文件打开错误\n");
exit(0);
}
while((ch=fgetc(f))!=EOF)
{
if(ch==' ')
{
t=1;
i=0;
}
if(t&&(ch>64&&ch<91||ch>96&&ch<123))
{
t=0;
word++;
p=(struct check *)malloc(N);
r->next=p;
r=p;
}
if(!t&&(ch>64&&ch<91||ch>96&&ch<123))
{
p->words[i]=ch;
i++;
}
}
r->next=NULL;
printf("单词数目为%d个\n",word);
}
void del_word() //末尾情况探讨
{
p=L->next;
while(p)
{
s=p;
r=p->next;
while(r)
{
if(!strcmp(p->words,r->words))
{
s->next=r->next;
delete r;
r=s->next;
}
if(r)
{
s=s->next;
r=r->next;
}
}
p=p->next;
}
}
void print()
{
f=fopen("3.txt","w");
p=L->next;
while(p)
{
printf("%s\n",p->words);
fprintf(f,"%s\n",p->words);
p=p->next;
}
fclose(f);
}