Ok...its been two days now and I can't get it yet! I googled for long hours but couldn't find what exactly I was looking for. So, here it is -
Say, I have a structure with only one element. (I'll add more elements to the structure once I get it to work!)
Code:
typedef struct
{
int roll;
}STUDENT;
Now when the program is run, I want the user to specify the number of students and then allocate the necessary memory using malloc(). So, I did this -
Code:
int num;
REC *pt;
pt= (REC *) malloc (num*sizeof(REC)); // I also tried this without casting!
Now, I am having difficulties in stroing the values and then displaying those values back to the screen. I used the following code -
Code:
printf("\n* * * * Enter roll no of students. * * * *\n");
for (i=0;i<num;i++)
{
printf("-->");
scanf("%d",(pt+i)->roll);
}
printf("\n* * * * Entered roll no. * * * *\n");
for (i=0;i<num;i++)
{
printf("%d, ",*(pt+i)->roll); //This is where the error occures!
}
when I try do compile it, I get the error "invalid type argument of `unary *'".
How can I solve this?
P.S. I am using wxdev C++.