2

I am reading a file that has some data in it. The data is not uniform. But once in a while there might be a line that have a file name and SHA1 sum value in it. I read the data line by line, and then when there is a line with SHA1 sum value, I use strtok, to get data in tokens. And I get SHA1 sum in a variable (e.g: char *hash).

Later in the program, I re-run SHA1 on the same file to get the hash sum (in a variable such as unsigned char hash[20]). Now I want to compare these to values, but I don't know how to approach that. Should I convert unsigned char array to char* or should I convert char* to unsigned char? or can I compare them without converting? And if conversion is needed, how to do this conversion. I found that sprintf can be used for that, but couldn't do it.

EDIT: I realized that this problem was part of another problem I had. I have posted that question here with code.

Community
  • 1
  • 1
Neo
  • 349
  • 5
  • 18
  • `unsigned char hash[20]` is not a simple variable, it is ARRAY or in other words `hash` is of type `unsigned char *`. – VolAnd Apr 02 '15 at 05:27
  • Conversion from `char` or `unsigned char` to pointer `unsigned char *` is incorrect (but possible), I think you should talk about conversion from `unsigned char` to `char` (it is possible) and placement such elements to array (address pointer by `char*`). – VolAnd Apr 02 '15 at 05:29
  • Your question would be clearer with a code sample. Are you asking how to convert a text series of hex digits into binary data? (or vice versa) – M.M Apr 02 '15 at 07:17
  • @MattMcNabb I found out i was asking the wrong question. I have posted another [question](http://stackoverflow.com/questions/29406857/comparing-sha-checksum-values-in-c). Don't know if i should link this to that. – Neo Apr 02 '15 at 07:41
  • @nEO if this question is no longer relevant in light of the other question, you can delete it – M.M Apr 02 '15 at 10:42

0 Answers0