malloc
hi there.
I have these two structures below: struct name{ char *firstn,*lastn; }; typedef struct name NAME; struct student{ NAME stname; int *mark; }*st; typedef struct student STUDENT; _________________________________________________________ I have 3 pointers:firstn,lastn and st and I'm going to use them as dynamic arrays. please tell me how to allocate dynamic memory for that in C. |
You answered your own question: you can "malloc()" each of the strings.
Stylistically, I'd lose the "typedefs". If you really insisted on using typedef's, however, I'd *definitely* include them in your struct definition: Code:
/* POOR */ Code:
// BEST If you're using C++, you might consider just using the Standard C++ "string" class. This eliminates the whole issue of what to "malloc()", when... |
All times are GMT -5. The time now is 03:42 PM. |