r/C_Homework • u/FoolJones • Oct 13 '20
Help with malloc !
So a bit of context, I'm doing my homework and the assignment is to do have a pointer that stores all the variables in the program. The program has to store, delete and list names.What I'm getting stuck at is this:
int main () {
pBuffer * buffer;
buffer->choice= (int *) malloc(sizeof(int));
...When it the malloc line the program simply stops, no error.
The pBuffer struct is written like this:
struct buf {
int * choice;
char * names;
char * character;
int * character_POS;
};
typedef struct buf pBuffer;I am trying to make it work for some days and still don't understand what is wrong. Some help is appreciated, thanks!
1
Upvotes
View all comments
Show parent comment
1
u/FoolJones Oct 14 '20
Thanks for the help!!
I did the changes and it worked as it was supposed to work just so I realize .... I misread what the questions was asking for .... goddammit. But thank you for helping me understand!