I need to change this to C++, including the last part of the comment meaning the
ID: 3901990 • Letter: I
Question
I need to change this to C++, including the last part of the comment meaning the checksums don't match.
Explanation / Answer
else if (data == "CS"){
cout<<"Comparing checksum for received file."<<endl;
checksum = conn.recv(buffer_size);
//create checksum of file
const size_t WORD_SIZE = sizeof(uint32_t);
file.seekg(0, ios::end);
auto sizeInBytes = file.tellg();
file.seekg(0);
uint32_t file_checksum = 0;
if(auto sizeInEntireWords = sizeInBytes / WORD_SIZE)
{
for(int i = 0; i < sizeInEntireWords; i++)
{
uint32_t word;
file.read(reinterpret_cast<char*>(&word), WORD_SIZE);
file_checksum += word;
}
}
if(checksum == file_checksum){
cout<<"checksum matched"<<endl;
return 1;
}
else{
cout<<"Error: Checksum dont match"<<endl;
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.