>>> 此贴的回复 >> 第一个字符就是 '\0'了怎么能显示出来.况且ptr还自加了.也就是ptr的指向发生了变化.
>>> 此贴的回复 >> CODE:[Copy to clipboard]#include #include #include #include #include #include #include #include
int main(int argc, char **argv) { int i, id; struct shmid_ds buff; unsigned char *ptr,*tmp;
if (argc != 2){ printf("usage: shmwrite
\n"); return -1; }
id = shmget(ftok(argv[1], 0), 1000, 0666|IPC_CREAT); ptr = (unsigned char *)shmat(id, NULL, 0); printf("shmid is %d\n",id); printf("ptr is %p\n",ptr); shmctl(id, IPC_STAT, &buff); memset(ptr,0,buff.shm_segsz);
printf("buff.shm_segsz is %d\n",buff.shm_segsz); tmp = ptr+1; for (i = 0; i < 255; ptr++,i++) *ptr = i%255; printf("ptr is %s\n",tmp); exit(0); } 我不知道你想实现的是不是这样的.