【发布时间】:2020-12-09 07:22:42
【问题描述】:
如何将 str "0xfa" 转换为 int 0xfa,str "0x5c" 转换为 int 0x5c ?
我的代码:
#include <stdio.h>
#include <string.h>
int main(){
char a[]="0xfa";
char b[]="0x5c";
int c=a;
int d=b;
//i have to get c to be 0xfa,and d to be 0x5c
printf("%c%c\n",(char)c,(char)d);
return 1;
}
【问题讨论】:
-
只是谷歌“将十六进制字符串转换为字符数组”
-
请注意,普通程序只有在失败时才返回 1,否则返回 0,尽管这通常没什么实际区别,除非您将其用作终端工具。
标签: c