I am just trying to learn C and trying to understand the structs and the pointers. One of the programs I wrote is getting compiler error as below:
:29:18: error: request for member 'price' in something not a structure or union.
Sample program :
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char *Title;
float price;
} Book;
int main()
{
int a = 10;
Book *HFJ = malloc(sizeof *HFJ) ;
HFJ->Title = "Head First Java";
HFJ->price = 200;
void *object;
object = &a;
printf("Value of object is %d", * (int*)object);
printf("Value of HFJ %f", HFJ->price);
object = HFJ;
(Book*)object->price = 300;
return 0;
}