struct data { u_short sin_port; structin_addr sin_addr; unsigned char id; };struct data Data[141];char *buf,*buf1, buf1 = (char *)malloc(10000); memset(buf1, 0, 10000);for (i =0;i< 141;i++){ memcpy(buf1, &Data[i].id,20); printf("buf11: %x", buf1); buf1+=20; memcpy(buf1, &Data[i].sin_addr, 4); buf1+=4; memcpy(buf1, &Data[i].sin_port, 2); buf1+=2; size1 += 26;}buf1 -= size1; write(fd2, buf1, size1+1); close(fd2); free(buf1);
我發(fā)現(xiàn)這樣寫入的數(shù)據(jù)總是不對/?請教哪里有問題???一般都是先寫入buffer,再寫入文件?