开发者

Can you please Explain the output and point out mistake

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", FramebufferUp开发者_如何学JAVAdateRequest[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


I think you wanted to write:

memset(FramebufferUpdateRequest, 0, 10);
FramebufferUpdateRequest[0] = '3'; //notice the difference
FramebufferUpdateRequest[1] = '1'; //notice the difference
val = '3';  //or var = ('3' << 1 | '3') if you want both bytes to have '3'
memcpy(FramebufferUpdateRequest+6, &val, 2);
val = '2';  //or var = ('2' << 1 | '2') if you want both bytes to have '2'

Know the difference between '1' and 1:

   cout << (int) ('1') << endl;
   cout << (int) (1) << endl;

Output: ( http://www.ideone.com/z3spn )

49
1

Explanation: '1' is a character literal, whose ascii value is 49, whereas 1 is an integer.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜