md5.digestFile

closed account (3v0MSL3A)
Hi, can anyone help me? I am new to C++ programming. I need to create a program that calculate the md5 checksum of the file that is input by user. At the moment, I managed to open the file and calculate the md5 checksum. But only if I write the path in my command

puts( md5.digestFile ("D:\\test.txt") ) ;

My problem is how can I write a command without need to write the path of the file as you can see above. I tried to write puts( md5.digestFile (pathA)) but it gives an error. I also tried to used other available command but it seems does not work.

digestFile (char *filename)
digestMemory (uint8_t const *memchunk, size_t len)
digestString (char const *string)
digestRaw
digestChars

This is my program but u can see it does not complete yet. Thank you.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <fstream>
#include <string.h>
#include <string>
#include "md5.h"

using namespace std;
int main()
{

/*******file that user wish to scan*******/

ifstream fileA ;
string pathA ;
cout << "Write the path of the file that you wish to scan\n" ;
cin >> pathA ;

if(!fileA )
{
cout << "Could not open the file " << pathA << endl ;
return 1 ;
}
else
{

/*******calculating md5 checksum of the file*******/

MD5 md5 ;
cout << "The MD5 checksum for file '" << pathA << "' is" << endl ;
puts( md5.digestFile ("D://test.txt") ) ;

/*******store the checksum in other file for comparing*******/

ofstream checksum ("D:\\md5checksum.txt");
if (checksum.is_open())
{
checksum << md5.digestFile ("D:\\test.txt") << endl ;
checksum.close();
}

/*******comparing checksum with virus database*******/

cout << "Checking in virus dictionary to find matching signature...\n" ;

}
return 0;
} 
Last edited on
Why did you a create a second thread? http://www.cplusplus.com/forum/general/211265/
Hello baeso,

See Thomas1965's comment "you need to open it or specify a filename when you create it: http://www.cplusplus.com/forum/general/211265/#msg989821

And jonnin;s point on paths http://www.cplusplus.com/forum/general/211265/#msg989824

Your above code does not open an input file. It does for output.

If you are going to use "puts" you are missing the "stdio.h" header file.

Hope that helps,

Andy

P.S. It would help to know what the "md5.h" file looks like because no one can test your code. And a sample of the .text file would not hurt.
Last edited on
Topic archived. No new replies allowed.