forked from akn714/1st-yr-c-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
31.c
39 lines (30 loc) · 813 Bytes
/
31.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
// Task : WAP to compare the contents of two files and determine whether they are same or not.
#include <stdio.h>
#include <stdbool.h>
int main(){
// declaring file pointers
FILE *file1, *file2;
// opening both files
file1 = fopen("text.txt", "r");
file2 = fopen("text2.txt", "r");
char ch1, ch2;
bool areEqual = true;
while(ch1 != EOF && ch2 != EOF){
ch1 = fgetc(file1);
ch2 = fgetc(file2);
if(ch1!=ch2){
areEqual = false;
break;
}
}
// closing both files
fclose(file1);
fclose(file2);
// printing if both files have same or differnet contents
if(areEqual){
printf("both files have same content\n");
}
else{
printf("both files have different content\n");
}
}