Alfred
Alfred

Reputation: 1663

No such file or Directory error for including header file C

I am trying to include a header file which contains a structure, but when I try to compile the file including the header file, I get No such file or Directory error. Both .c and header file are in the same directory.

Here is the code:

Header file "MyShared.h":

#ifndef MYSHARED_H_INCLUDED
    #define MYSHARED_H_INCLUDED
    #define PERM (S_IRWRU | S_IRGRP)
    #define MySharedKey 0343
    #define SIZE 2048

    struct MyShared
    {
        char *buf[SIZE];
        int ReadfromBuf,WriteToBuf,readbytes;
    };
#endif

Mem.c file including the header file:

#include <sys/shm.h>
#include "MyShared.h"

int main()
{
    MyShared *obj;

    int shmid,i,childpid;

    shmid = shmget(MySharedKey,sizeof(MyShared),NULL);

    .....
}

Why am I getting this error?

Upvotes: 0

Views: 2932

Answers (1)

wildplasser
wildplasser

Reputation: 44220

In C, a struct definition is not a typedef.

#include <sys/shm.h>
#include "MyShared.h"


int main()
{
struct MyShared *obj;

int shmid,i,childpid;

shmid=shmget(MySharedKey, sizeof *obj, NULL);

    .....
}

BTW: I don't think you want an array of pointers in shared memory: char *buf[SIZE]; should probably be char buf[SIZE];

Upvotes: 1

Related Questions