struct data { u_short sin_port; struct in_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);
我发现这样写入的数据总是不对/?请教哪里有问题啊?一般都是先写入buffer,再写入文件?
……
一周热门 更多>