I have below program for shared memory access in 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);
}
In this program I am getting error for below line
*s = NULL;
Error:
shm_server.c: In function ‘main’:
shm_server.c:36:8: warning: assignment makes integer from pointer without a cast [enabled by default]
Why am I receiving this error?
Note: I also have a other script as shm_client.c to read the memory while the server program shm_server.c waits till client program changes the first character to '*'