Im just learning C and I need help. Im trying to allocate memory for a structure call mystruct, initialize the values for the strucutre and then return a pointer to the allocated memory:

void main(){
struct mystruct pdemo;
pdemo=alloc_mystruct(buf1,buf2,val1);
}

struct mystruct *alloc_mystruct(char *name,const char *id,int val){
struct mystruct *pMyStruct;

pMyStruct->name=(char*)malloc(sizeof(name));
pMyStruct->id=(char*)malloc(sizeof(id));
pMyStruct->val=malloc(sizeof(val));

strcpy(pMyStruct->name, name);
strcpy(pMyStruct->id, id);
pMyStruct->val=val;

return pMyStruct;
}

could someone please point out what im doing wrong here?