[Solved] make some crc check code, loop for multiple file (c++)


I made several changes to your code. I removed guard headers since we use it only in header files. Old-fasioned memset has been replaced by operation on strings. I suspect that you need to pass char* to CCRC32 object hence sSourceFile is still const char*. I compiled code except parts with CCRC32.

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "../CCRC32.H"

int main(int iArg, char *sArg[])
{
  std::vector<std::string> filenames;
  // TODO - populate filesnames (paths?)

  CCRC32 crc32;
  crc32.Initialize(); //Only have to do this once.

  for (unsigned int i = 0; i < filenames.size(); i++) {
    const char* sSourceFile = filenames[i].c_str();

    unsigned int iCRC = 0;
    int compare = 399857339;    // TODO - you need to change this since you are checking several files

    std::ifstream checkfile(sSourceFile);
    if (checkfile) {

      std::cout << "Checking file " << sSourceFile << "..." << std::endl;
      crc32.FileCRC(sSourceFile, &iCRC);

      if(iCRC == compare){
        std::cout << "File " << sSourceFile << " complete!\nCRC Result: " << iCRC << std::endl;
      } else {
        std::cout << "File " << sSourceFile << " incomplete!\nCRC Result: " << iCRC << std::endl;
      }
    } else {
      std::cout << "File tidak ditemukan!" << std::endl;
    }
  }

  return 0;
}

0

solved make some crc check code, loop for multiple file (c++)