typedef union
{
uint ui[4];
} md5hash;
void main(void)
{
int opt;
while ((opt = getopt(argc, argv, "c:t:s:h:")) != -1) {
switch (opt) {
case 'h':
hash = optarg;
break;
default: /* '?' */
exit(EXIT_FAILURE);
}
}
md5hash hash;
sscanf(hash, "%x%x%x%x", &hash.ui);
}
Run Code Online (Sandbox Code Playgroud)
./program -h fffffffffffffffffffffffffffffffff
我想做上面的事情,但是sscanf不能正确地接受md5sum ......
sscanf语句试图回读hash自己,但显然它不会找到任何十六进制数字.%x 可能会在不同平台上以十六进制加载不同大小的整数,因为您没有为每个字段指定任何特定长度.如果你有一个十六进制字符串,那么让我们说hashString你可以试试
int fieldsScanned = sscanf (hashString, "%8x%8x%8x%8x", &hash.ui[0], &hash.ui[1], &hash.ui[2], &hash.ui[3]);
if (fieldsScanned == 4)
{
// MD5 sum is in hash variable.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
335 次 |
| 最近记录: |