Receiving error: assignment makes integer from pointer without a cast

Receiving error: assignment makes integer from pointer without a cast

我有以下 C 语言的共享内存访问程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#define SHMSZ 27

int main() {
    char c;
    int shmid;
    key_t key;
    char *shm, *s;

    key = 5678;
    /* Create the segment */
    if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
        perror("shmget");
        exit(1);
    }

    /* Attach the segment */
    if ( (shm = shmat(shmid, NULL, 0)) == (char *) -1) {
        perror("shmat");
        exit(1);
    }

    /* Put things into memory for other processes to read*/
    s = shm;
    for (c = 'a'; c <= 'z'; c++) {
        *s++ = c;
    }
    *s = NULL; 

    /*Wait till other processes read and change the memory*/
    while (*shm != '*') {
           sleep(1);
    }

    exit(0);
}

在这个程序中,我收到以下行的错误

   *s = NULL;

错误:

shm_server.c: In function ‘main’:
shm_server.c:36:8: warning: assignment makes integer from pointer without a cast [enabled by default]

为什么我会收到此错误消息?

注意:我还有另一个脚本 shm_client.c 来读取内存,而服务器程序 shm_server.c 等待客户端程序将第一个字符更改为 '*'

如果你想在数据末尾写 'null' 而不是 'NULL' 那么这样做:

*s = '[=10=]'; 

*s  = 0x00;