Hi All,
I am trying to read from the file and then copy to the shared memory.
While doing strcpy i get SIGSEGV.
Can any body can help here like what is the root cuase of the issue?
Code:
#include<sys/ipc.h>
#include <stdio.h>
#include<sys/shm.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
int k,shmid;
void *data;
FILE *fp;
char *ptr;
ptr = calloc(20,1);
memset(ptr,20,0);
k=ftok(".",20);
shmid=shmget(k, 1000, 0);
data=shmat(shmid,(void*)0,0);
fp = fopen(argv[1],"r");
fread(ptr,1,10,fp);
strcpy((char *)data,ptr);
fclose(fp);
exit(0);
}