_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s\n", i, buffer );
_ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s\n", l,
buffer );
_ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
buffer );
}
Output
String of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2
TCHAR str[255]={_T('\0')};
_stprintf(str,_T("%d"),lScore);
SetWindowText(hwnd,str);
37。我用socket发送的的buf中间需要的是 char *类型的数据,我想将一个 struct 直接转换成 char * 发过去。
我用
struct ABCD *abcd;
char *buf;
abcd = (ABCD *)calloc(1,sizeof(ABCD));
buf = (char *)calloc(1,sizeof(ABCD));
///
给abcd 中间赋值,其中有多个char[]的值和int 的值
///
memcpy(buf,abcd,sizeof(ABCD));
//strcpy(buf,(char *)abcd);也不可以
sock(host,buf,....);
//sock(host,(char *)buf,...);也不可以
问题就是在这里,这个buf中间的值总是不对,大家知道为什么否。
你传的是个指针值,而不是数据
但是用memcpy这个是将整个数据都复制过去
你用的VC???改成ABCD *abcd;后编译一点问题也没有啊!
sock(host,buf,....);这不知是什么,自定义函数?
typedef struct _ABCD
{
int ID;
char Name[10];
}ABCD;
.......
ABCD *abcd;
char *buf;
abcd = (ABCD *)calloc(2,sizeof(ABCD));
buf = (char *)calloc(2,sizeof(ABCD));
///
//给abcd 中间赋值,其中有多个char[]的值和int 的值
abcd[0].ID =1;
abcd[1].ID =2;
///
memcpy(buf,abcd,2*sizeof(ABCD));
strcpy(buf,(char *)abcd);//也不可以
buf中的内容也正确!!
我按照楼上的兄弟说的,做了一下,但是仍然做不下来,我用
memcpy(buf,abcd,sizeof(ABCD));
中间的abcd,不知道是不是地址的问题。
老大,你sizeof()得出的数值事多大,看看吧。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27731-18.html
对于进入12海里的外国舰船也不是立马就给予击沉和撞击