This repository has been archived by the owner on Oct 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoOverlap.c
103 lines (95 loc) · 1.8 KB
/
noOverlap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct file
{
char line[210];/*This must be larger if the word is longer.*/
struct file *next;
}_fe;
_fe *load_cmp(FILE *fpin)
{
int i = 0;
char ch;
_fe *pre_head,*tail,*find;
pre_head = (_fe*)malloc(sizeof(_fe));
tail = pre_head;
_fe *kanji = (_fe*)malloc(sizeof(_fe));
while((ch = fgetc(fpin)) != 0xa)
kanji->line[i++] = ch; /*Without EOF judgement,if file have only one line,a pointer have not been free.*/
kanji->line[i] = '\0';
kanji->next = NULL;
tail->next = kanji;
tail = kanji;
while(1)
{
find = pre_head;
_fe *kanji = (_fe*)malloc(sizeof(_fe));
for(i = 0;(ch = fgetc(fpin)) != 0xa;i++)
{
if(ch == EOF)
{
free(kanji);
return pre_head;
}
kanji->line[i] = ch;
}
kanji->line[i] = '\0';
while(find != tail)
{
find = find->next;
if(strcmp(kanji->line,find->line) == 0)
{
printf("%s\n",kanji->line);
free(kanji);
i = -1;
break;
}
}
if(i >= 0)
{
kanji->next = NULL;
tail->next = kanji;
tail = kanji;
}
}
}
void free_load_p(_fe *head)
{
_fe *pointer = head;
while(head)
{
pointer = pointer->next;
free(head);
head = pointer;
}
}
void output_file(FILE *fpout,_fe *head)
{
_fe *suf_head = head;
_fe *pointer = suf_head->next;
while(pointer)
{
fputs(pointer->line,fpout);
fputc(0xa,fpout);
// fprintf(fpout,"%s\n",pointer->line);
pointer = pointer->next;
}
}
int main()
{
FILE *fpin,*fpout;
/* char input[60] = "";
printf("Please input the file which to be processed:");
scanf("%s",input);
*/ if((fpin = fopen("pyPhrase.org","r")) == NULL || (fpout = fopen("tmp.txt","w")) == NULL)
{
printf("Can't open file.");
return 0;
}
_fe *head = load_cmp(fpin);
output_file(fpout,head);
free_load_p(head);
fclose(fpin);
fclose(fpout);
return 0;
}