By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,983 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,983 IT Pros & Developers. It's quick & easy.

C++ Program to read and compare two files Character by character

P: 3
Hi here is the program description
" Write a C++ program that prompt the user for the names of the two files and then it compares the files. Assume each file has five lines of text. The program should prints a message indicating that the files are exactly the same or that there are differences by comparing each line from file1 with file2. If the files are different, the program should print the line numbers for lines that are not the same. Your program should also analyse one of the files (e.g. file1) where it should print the number of characters in the file, maximum number of characters per line, minimum number of characters per line, and the average number of character per line."

HELP ME PLEASE...
i know how to read from a text file but i dont know how to compare it..
thanks.
Oct 25 '15 #1
Share this Question
Share on Google+
7 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
OK. Let's see the code where you read from the files.
Oct 25 '15 #2

P: 3
I don't know how to write code correctly?
I am a novice ��
Oct 25 '15 #3

P: 1
well, i think you mean this one.


Oct 25 '15 #4

P: 3
Yes , That what I mean
Oct 25 '15 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
I won't write the code for you. But I can help you to write it.

So post some code where you open a text file and read one record from it.

Do not get fancy and ask for user input. Hard-code the file name. You can add the fancy later.

I notice the data files mention C++. If yours is a C++ class, try to write in C++.
Oct 25 '15 #6

P: 1
hello,
same question to compare file 1 and file 2 line by line using if statement: If the files are different, the program should print the line numbers for lines that are not the same

so for example
if (line1file1!=line1file2)
{
cout<<"message indicating where the difference is at";
}

then to continue this again and again for the other lines. would that be right?
Oct 26 '15 #7

weaknessforcats
Expert Mod 5K+
P: 9,197
Please read my Post #6 again.

It is pointless to worry about comparing files if you cannot open a file and read a record.

Once you write that code, it can be expanded to open the other file and read a record there.

THEN you worry about comparing the two files.

Please post again.
Oct 26 '15 #8

Post your reply

Sign in to post your reply or Sign up for a free account.