你能解释一下输出并指出错误吗
char FramebufferUpdateRequest[11];
uint16_t val;
memset(FramebufferUpdateRequest, 0, 10);
FramebufferUpdateRequest[0] = 3;
FramebufferUpdateRequest[1] = 1;
val = 3;
memcpy(FramebufferUpdateRequest+6, &val, 2);
val = 2;
memcpy(FramebufferUpdateRequest+8, &val, 2);
FramebufferUpdateRequest[10]='\0';
printf("framerequest :: %c %s\n", FramebufferUpdateRequest[1], FramebufferUpdateRequest);
这个 printf 的输出是空白,即“framerequest ::”。有人能指出我做错了什么吗?
在 gcc 4.1.2 中编译
char FramebufferUpdateRequest[11];
uint16_t val;
memset(FramebufferUpdateRequest, 0, 10);
FramebufferUpdateRequest[0] = 3;
FramebufferUpdateRequest[1] = 1;
val = 3;
memcpy(FramebufferUpdateRequest+6, &val, 2);
val = 2;
memcpy(FramebufferUpdateRequest+8, &val, 2);
FramebufferUpdateRequest[10]='\0';
printf("framerequest :: %c %s\n", FramebufferUpdateRequest[1], FramebufferUpdateRequest);
output of this printf is Blank i.e "framerequest :: ".Can anyone point out what I am doing wrong?
compiled in gcc 4.1.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你想写:
了解
'1'
和1
之间的区别:输出:( http://www.ideone.com/z3spn )
解释:
'1'
是一个 字符文字,其 ascii 值为49
,而1
是一个整数。I think you wanted to write:
Know the difference between
'1'
and1
:Output: ( http://www.ideone.com/z3spn )
Explanation:
'1'
is a character literal, whose ascii value is49
, whereas1
is an integer.您正在将不可打印的字符分配给
FramebufferUpdateRequest
。您需要以某种方式将其转换为整数(即使用循环和
%d
)或可打印字符(例如,向每个元素添加'A'
)。维基百科显示了基本的可打印字符集。
You are assigning unprintable characters to
FramebufferUpdateRequest
.You will need to somehow convert it either to integers (ie. use a loop and
%d
) or printable characters (for example, add'A'
to every element).The basic set of printable characters is shown at Wikipedia.