-1

I have a following typedef in my C program which throws an error.This is part of my code-

typedef struct Room
{
    int ** values;
}Room;

int createRoom(Room pm) // it give me error unknown type Room
{
    //some code here
}

int main()
{
    Room *pm;
    pm=(Room)malloc(sizeof(Room));
    int n=callfun(pm);
    return 0;
}

It gives me unknown type Room error. Also, I get an error in the malloc line. Can anyone tell me where I am wrong

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173

2 Answers2

0
 pm=(Room)malloc(sizeof(Room));

Should be,

 pm=(Room*)malloc(sizeof(Room));

pm is Room*.

As stated in comment, as malloc return void * you need not to cast it, so it can be,

pm=malloc(sizeof(Room));
Pranit Kothari
  • 9,721
  • 10
  • 61
  • 137
0
pm=(Room)malloc(sizeof(Room));

should be

pm=(Room *)malloc(sizeof(Room));

Don't cast malloc()

Just do

pm= malloc(sizeof(Room));
Community
  • 1
  • 1
Gopi
  • 19,784
  • 4
  • 24
  • 36
  • I fixed that error of `unknown type room`.Now I am getting this error- `incompatible implicit declaration of built-in function malloc` –  Feb 17 '15 at 04:51
  • @Coder `#include` – Gopi Feb 17 '15 at 05:14