>>> 此貼的回復 >> 第一個字符就是 '\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); } 我不知道你想實現的是不是這樣的.