首先定義兩個結構體:
struct udpdata
;struct scanudpdata
{short* itotaly;
long* ltotalx;
udpdata* udpdata;
int callnum; //udpthread收資料的次數
然後給結構體賦值:
pdata = new udpdata; //注意:此處要new乙個udpdata,否則程式出現access violation錯誤!!
pdata->sockudp = sockudp;
pdata->addrudp = addrudp;
pscanudpdata = new scanudpdata;
pscanudpdata->udpdata = pdata; //將new的pdata賦值給udpdata
//itotaly、ltotalx儲存所有接收到的資料
short* itotaly = (short*)malloc(max_data_len*sizeof(short));
long* ltotalx = (long*)malloc(max_data_len*sizeof(long));
memset(itotaly, 0, max_data_len*sizeof(short));
memset(ltotalx, 0, max_data_len*sizeof(long));
pscanudpdata->itotaly = itotaly;
pscanudpdata->ltotalx = ltotalx;
pscanudpdata->callnum = 0;
結構體賦值問題
如下面 所示,在給結構體變數賦值時,特別是結構體中的結構體成員變數,需要注意賦值方式。include stdio.h struct time struct date struct datelist void main struct date d3 struct date d2 struct date...
c語言結構體賦值問題
對於結構體賦值問題 1 static psl 我過去一般會對結構體這樣賦值 static psl pslname 記住有一點,b 後面的逗號可有可無,至於具體為什麼,我只能理解自己能力還不夠。現在只知道可有可無。上面這種賦值方式是對的。看看下面的一種賦值方式 static psl pslname 這...
結構體賦值是覆蓋的問題
include stdio.h include stdlib.h include string.h include conio.h typedef struct uploaduserinfo upload element char s nation 3 gg char s address 70 dd...