I wrote a python 3 script which checks if 2 output text files of C code are identical. 1 file is the "wanted" output text file which i got as an example of an input/output file with the assignment, and the other is the output file which my C code has given as output.
import filecmp
f1="out1.txt" #the output file i got from the assignment as example
f2="myout1.txt" #the output file my c code gave for the same input file of f1
f2_copy="myout1 (copy).txt" #copy of f2
print(filecmp.cmp(f1,f2))
print(filecmp.cmp(f2,f2_copy))
and i get as output:
>>>False
>>>True
even-though the files are identical, I get False as an output. The only way i get True is when i copy the file and then do filecmp.cmp...
if it matters, I'm using Ubunto and GCC to get the output file...
thanks.
EDIT1: I made a function which reads the lines of each file and compare the 2 lists:
def textCompare(fl1,fl2):
file1 = open(fl1, 'r')
file2 = open(fl2, 'r')
lines1=file1.readlines()
lines2=file2.readlines()
f1.close()
f2.close()
if lines1 == lines2:
return True
else:
return False
as I see, for my purposes it works fine... my question is what is the diffrence between this function and filecmp.cmp() that my function doesnt check?