在mfc中怎样将从edit框内获取到的CString类型的数据转化为unsigned char类型的数组,跪求大神了。
如:在edit框内输入ffffffffffff转化出来为0xff,0xff,0xff,0xff,0xff,0xff....
如:在edit框内输入ffffffffffff转化出来为0xff,0xff,0xff,0xff,0xff,0xff.
展开
1个回答
展开全部
CString s1 = "ffffffffffff";
char *s2 = (char *)(LPCTSTR)s1;
int nLen = strlen(s2);
int i = 0;
char s3[3] = {0};
while(i < nLen)
{
strncpy(s3, s2+i, 2);
i+= 2;
int n1 = 1;
sscanf(s3, "%02X", &n1);
unsigned char c1 = n1; // 此处得到unsigned char类型, 如果需要数组自己处理
printf("0x%02x,", c1);
}
char *s2 = (char *)(LPCTSTR)s1;
int nLen = strlen(s2);
int i = 0;
char s3[3] = {0};
while(i < nLen)
{
strncpy(s3, s2+i, 2);
i+= 2;
int n1 = 1;
sscanf(s3, "%02X", &n1);
unsigned char c1 = n1; // 此处得到unsigned char类型, 如果需要数组自己处理
printf("0x%02x,", c1);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询