I'm trying to figure out where my problem is and can't seem to find it, I want to a allocate dynamic memory to a variable within a struct, I have tried in all sorts of ways and it just does not work I get a warning: Exception has occurred. segmentation fault
When I allocate memory to the *bookcase its works but when i try to allocate to a variable within the structure i get the warning.
example of what I was trying to do
struct book
{
int num;
char* book_name;
}*bookcase;
void addbook(void)
{
char buff[20];
gets(buff);
bookcase->book_name = ( char *)malloc(strlen(buff));
strcpy(bookcase->book_name,buff);
}
Sorry for the question feels really stupid, unfortunately i could not understand the problem, Any help would be appreciated. Thank you.