问题描述
我有一个程序我要打印一个字符串
" 457e31b2db200dc125f3e00886ff57de"
like" ; \ x45 \ x7e \\ xx2 \ xb2 \xdb \ x20 \x0d \ xc1 \ x25 \ xf3 \xe0 \ x08 \ x86 \ xff \ x57 \ xx"
..但是在每一个案例中它都给出了一个错误:
test.c:16:9:\ x使用没有以下的十六进制数字
********* Test.c ****************
#包括< stdio.h>
#include< stdlib.h>
#include< string.h>
#include< ; locale.h>
#include< wchar.h>
int main(int argc,char * argv [])
{
int i;
unsigned char mbBuf [16] =" 457e31b2db200dc125f3e00886ff57de" ;;
for(i = 0; i< ; 16; i ++)
printf(" \ x%02",mbBuf [i]);
}
需要帮助!!
printf(" \\x%02",mbBuf [i]);
当你想要a \出现在输出字符串中,你必须通过加倍来转义\
。\\ / $
-
否一个人有权通过要求经验证据来摧毁另一个人的信念。 - Ann Landers
[OP在EOM的代码]
#包括< stdio.h>
int main(无效)
{
unsigned char mbBuf [] =" 457e31b2db200dc125f3e00886ff57de" ;;
unsigned i,n = sizeof mbBuf - 1;
for(i = 0; i< n; i + = 2)
printf(" \\\\ %% c%c",mbBuf [i],mbBuf [i + 1]);
返回0;
}
[OP'代码]
printf(" \\x%02",mbBuf [i]);
错误的代码。你不打印mbBuf [i]。
#include< stdio.h>
#include< stdlib.h>
int main(无效)
{
int i;
/ *偶数个字符! * /
unsigned char mbBuf [] =" 457e31b2db200dc125f3e00886ff57de" ;;
for(i = 0; i<(sizeof(mbBuf)/ sizeof(mbBuf) [0]))/ 2; i ++){
printf(" \\x%c%c",mbBuf [2 * i],mbBuf [2 * i + 1]) ;
}
printf(" \ n");
返回EXIT_SUCCESS;
}
-
Giorgio Silvestri
DSP /嵌入式/实时操作系统(RTOS)软件工程师
Hi ,
I have a program where I want to print a string
"457e31b2db200dc125f3e00886ff57de"
like "\x45\x7e\x31\xb2\xdb\x20\x0d\xc1\x25\xf3\xe0\x08\ x86\xff\x57\xde"
.. But in each and every case it is giving an error :
test.c:16:9 : \x used with no following hex digits
*********Test.c****************
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <wchar.h>
int main(int argc, char* argv[])
{
int i;
unsigned char mbBuf[16] = "457e31b2db200dc125f3e00886ff57de";
for(i=0;i<16;i++)
printf("\x%02",mbBuf[i]);
}
Need help !!
printf("\\x%02",mbBuf[i]);
When you want a \ to appear in the output string, you have to
escape the \ by doubling it.
--
"No one has the right to destroy another person''s belief by
demanding empirical evidence." -- Ann Landers
[OP''s code at EOM]
#include <stdio.h>
int main(void)
{
unsigned char mbBuf[] = "457e31b2db200dc125f3e00886ff57de";
unsigned i, n = sizeof mbBuf - 1;
for (i = 0; i < n; i += 2)
printf("\\x%c%c", mbBuf[i], mbBuf[i + 1]);
return 0;
}
[OP''s code]
printf("\\x%02",mbBuf[i]);
Wrong code. You don''t print mbBuf[i].
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
/* even number of chars !!! */
unsigned char mbBuf[] = "457e31b2db200dc125f3e00886ff57de";
for(i=0;i<(sizeof(mbBuf) / sizeof(mbBuf[0]))/2;i++) {
printf("\\x%c%c",mbBuf[2*i],mbBuf[2*i+1]);
}
printf("\n");
return EXIT_SUCCESS;
}
--
Giorgio Silvestri
DSP/Embedded/Real Time OS (RTOS) Software Engineer
这篇关于\ x使用时没有以下十六进制数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!