Converting char* to unsigned char array C

余生长醉 提交于 2019-12-11 03:06:47

问题


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.

来源:https://stackoverflow.com/questions/29405538/converting-char-to-unsigned-char-array-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!