You want to implement a function that reads a directory of files stored in Notepad and calculates hash values and stores the resulting values in variables.
First of all, the Notepad (File_list.txt) is stored in the following format:
And when you operate file_hash() in main, the following execution result is printed.
Error opening file C:\search\temp\md5.c Error: 2
Error opening file C:\search\temp\md5.h Error: 2
Error opening file C:\search\temp\Test.txt Error: 123
After that, I looked at the contents of the error through googling Error 2 indicates that the system cannot find the specified file. Error 123 has invalid file name, directory name, or volume label syntax.
Direct delivery of the function as a factor, such as L"C:\search\temp\Test.txt", works and retrieving the contents of the notepad one line at a time through fgets(), results in an error as in the above case. That's why fgets() doesn't work the way you want it to because of the way they get the string
I wonder if it is a problem with the process of converting a string to Unicode (? An example of this MD5 hash function was taken from https://docs.microsoft.com/ko-kr/windows/win32/seccrypto/example-c-program--creating-an-md-5-hash-from-file-content and modified accordingly.c
When you read a line from a file with the fgets function, it reads not only one line, but also a new line character ('\n') at the end of the line.
For example, if you have a text file such as the following,
The first value read as fgets is "test2.txt\n". In this state, if you try to open a test2.txt file with this string, it says it is missing because of \n at the end.
On the other hand, since there is no \n after the last line of the above file, test3.txt, the value read in fgets is "test3.txt", in which case you can open the test3.txt file.
Therefore, if you want to read and use the file name with fgets, you can read one line, and if the last column is \n, fill in the column with a null character (0).
Please refer to the code below.
© 2022 pinfo. All rights reserved.