我想知道C中的变量值

时间:2019-07-11 04:21:28

标签: c

我是C语言的新手。

我想知道变量值。所以我写下来

    #include <stdio.h>

    int main(void) {
        unsigned char cdata[3];
        sprintf(cdata, "%0.2X", 0x42);
        printf(%hhu, cdata)
        return 0;
    }

但是有这样的错误

prog.c: In function ‘main’:
prog.c:5:10: warning: pointer targets in passing argument 1 of ‘sprintf’ differ in signedness [-Wpointer-sign]
  sprintf(cdata, "%0.2X", 0x42);
          ^~~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:366:12: note: expected ‘char * restrict’ but argument is of type ‘unsigned char *’
 extern int sprintf (char *__restrict __s,
            ^~~~~~~
prog.c:5:17: warning: '0' flag ignored with precision and ‘%X’ gnu_printf format [-Wformat=]
  sprintf(cdata, "%0.2X", 0x42);
                 ^~~~~~~
prog.c:6:9: error: expected expression before ‘%’ token
  printf(%hhu, cdata)
         ^
prog.c:7:2: error: expected ‘;’ before ‘return’
  return 0;
  ^~~~~~

0 个答案:

没有答案