-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.c
96 lines (75 loc) · 1.79 KB
/
14.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
#include<stdio.h>
#include<conio.h>
void main() {
FILE *fout1, *fout2, *fout3, *fin1, *fin2, *fin3;
char data1[30], data2[30], ch1, ch2, ch3;
clrscr();
fout1 = fopen("file1.txt", "w");
fout2 = fopen("file2.txt", "w");
if(fout1 == NULL) {
printf("Could not open file1");
getch();
exit(0);
}
if(fout2 == NULL) {
printf("Could not open file2");
getch();
exit(0);
}
printf("Enter content for file1:\n");
gets(data1);
printf("Enter content for file2:\n");
gets(data2);
fprintf(fout1, "%s", data1);
fprintf(fout2, "%s", data2);
fclose(fout1);
fclose(fout2);
fin1 = fopen("file1.txt", "r");
fin2 = fopen("file2.txt", "r");
fout3 = fopen("file3.txt", "w");
if(fin1 == NULL) {
printf("Could not read from file 1");
getch();
exit(0);
}
if(fin2 == NULL) {
printf("Could not read from file 2");
getch();
exit(0);
}
if(fout3 == NULL) {
printf("Could not open file 3");
getch();
exit(0);
}
ch1 = getc(fin1);
ch2 = getc(fin2);
while(ch1 != EOF && ch2 != EOF) {
if(ch1 != ch2) {
fputc(ch2, fout3);
}
ch1 = getc(fin1);
ch2 = getc(fin2);
}
fclose(fin1);
fclose(fin2);
fclose(fout3);
fin3 = fopen("file3.txt", "r");
if(fin3 == NULL) {
printf("Could not read from file 3");
getch();
exit(0);
}
if((ch3 = getc(fin3)) == NULL) {
printf("No difference between file1 and file2");
getch();
exit(0);
}
printf("Differences between file1 and file2 are:\n");
while(ch3 != EOF) {
printf("%c", ch3);
ch3 = getc(fin3);
}
fclose(fin3);
getch();
}