打印到屏幕上的结果为什么会乱码?
#include <stdio.h>typedef enum {INT, SHORT, CHAR} type;
void print(const void* p_shu_zi,type t) {
switch(t) {
case INT:
printf("%d\n",*(const int*)p_shu_zi);
break;
case SHORT:
printf("%hd\n",*(const short*)p_shu_zi);
break;
case CHAR:
printf("%c\n",*(const char*)p_shu_zi);
break;
}
}
int main() {
int shu_zi = 7;
char zi_fu = 'A';
short duan = 17;
printf(&shu_zi, INT);
printf(&zi_fu, CHAR);
printf(&duan, SHORT);
return 0;
}
--------------------Configuration: 29whl - Win32 Debug--------------------
Compiling...
29whl.c
G:\C语言编程\WHL\29whl\29whl.c(23) : warning C4133: 'function' : incompatible types - from 'int *' to 'const char *'
G:\C语言编程\WHL\29whl\29whl.c(25) : warning C4133: 'function' : incompatible types - from 'short *' to 'const char *'
29whl.obj - 0 error(s), 2 warning(s)
打印的结果:
A烫?Press any key to continue