Memcpy Seg Fault

I haven't included all my code because memcpy is the cause of my seg fault. I thought I was doing this right because both arrays are the same size. What am I doing wrong? Any help would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
typedef struct {
    long mtype;
    char mtext[4096];

} mymsg_t;
static int queueid;
//parent process sends to queue child process receives from queue

int main() {
    int size = 0;
    
    int maxsize = 4096;
    char boof[4096];
    fstream filestr;
    filestr.open("testfile4k.txt", fstream::in);
    while(filestr>>boof[size] && size < maxsize)
    {  
        size++;
    }
    filestr.close();
    cout<<size<<endl;
    
    int msgqid;
    mymsg_t *mymsg;
    int len = 4096;
    struct timeval tv;
    time_t curtime;
    char buffer[4096];
    memcpy(mymsg->mtext, boof, maxsize);
closed account (S6k9GNh0)
mymsg points to garbage. Also, what's the while loop expression doing?
Last edited on
allocate memory to *mymsg, before passing it to memcpy. mymsg pointer is dangling.
Thanks forgot to do that.
Topic archived. No new replies allowed.