Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is C + + program that I am running in with a lot of issues. So it suppoce to be a file comparison program.
This is C program that I am running in with a lot of issues.
So it suppoce to be a file comparison program. File has a lot of text that is located on one line only. File has the same text but is on many lines. This program should compare two of these files. If the program runs into a
diffrence it gives the option to skip a certain amount of characters. So the program countinues to compare from the same character in the files Done because The issues in each file could be diffrent lengths.
Also it prints the issues to display where the issue is present.
biggest issue is that when program file runs in to the end of line it does not get the text from line to countinue comparing and ends the program.
Can the issue be fixed since I cant get it to run the way I want. Thank you.
#include
#include
#include
#include
bool compareFilesconst std::string& filePath const std::string& filePath
std::ifstream filefilePath filefilePath;
if filefile
std::cerr "Error: Unable to open files." std::endl;
return false;
std::string line line;
std::vector lines;
while std::getlinefile line
if lineempty
linespushbackline;
sizet lineIndex ;
sizet fileCharCount ;
sizet fileCharCount ;
bool filesIdentical true;
while std::getlinefile line
if lineempty lineIndex linessize
break;
bool differenceFound false;
for sizet i ; i linelength && fileCharCount i lineslineIndexlength; i
fileCharCount;
fileCharCount;
if linei lineslineIndexfileCharCount
std::cout filePath Difference at position: fileCharCount std::endl;
std::cout linesubstri std::endl;
std::cout std::endl;
std::cout filePath Difference at position: fileCharCount std::endl;
std::cout lineslineIndexsubstrfileCharCount std::endl;
std::cout std::endl;
filesIdentical false;
std::cout "File shift forward: ;
sizet moveForward;
std::cin moveForward;
fileCharCount moveForward;
std::cout "File shift forward: ;
sizet moveForward;
std::cin moveForward;
fileCharCount moveForward;
std::cin.ignorestd::numericlimits::max
;
line linesubstri moveForward;
differenceFound true;
break;
if differenceFound
lineIndex;
fileCharCount ;
return filesIdentical;
int main
std::string file file;
std::cout "Enter path to File: ;
std::cin file;
std::cout "Enter path to File: ;
std::cin file;
if compareFilesfile file
std::cout "Files are identical." std::endl;
else
std::cout "Files are different." std::endl;
return ;
Wanted ouput:
main filetxt filetxt
file Difference at position:
Candiisup","lunchtimecodede"WantToGetzitsmartis
fil Difference at position:
Candiisup","lunchtimecodede"WantToGetzitsmarti
File shift forward:
File shift forward:
file Difference at position:
scountdownsPasseddensed:'Capess'sometimes::::"sun"""compar
file Difference at position:
qcountdownsSUNsed:'Capess'sometimes::::"sun"""comparePeepM
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started