C语言中如何将某个字符串转为16进制ascii码并输入到另一个字符串中?

如题所述

用sprintf()函数就可以了。
sprintf(*dst,"%x",*src)
dst:目标字符串
scr:源字符串
我回去试了一下,不行
一般的sprintf(*dst,"%s",*src)能把src转换成指定的格式
可是sprintf(*dst,"%x",*src)时,*dst存了地址!·

修改了一下,以下是例子,有效果了:
#include "stdafx.h"
#include<stdio.h>
void main()
{
char a[9]="a1234",b[20], *p=a;
int j=0;
while(*p!=0){ j+=sprintf(b+j,"%x",*p++);}
printf("%s\n",b);

}
参考资料:http://baike.baidu.com/view/1295144.htm#3(百度百科)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-03
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char result[100];
result[0]=NULL;
void toascii_16(char from[],int size,char *result)
{ char temp[10];
for(int i=0;i<size;i++) {
itoa(from[i], temp, 16);
strcat(result,temp);
}
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网