Allocating memory in char * struct
- by mrblippy
hi,
im trying to read in a word from a user, then dynamically allocate memory for the word and store it in a struct array that contains a char *. i keep getting a implicit declaration of function âstrlenâ so i know im going wrong somewhere.
struct class
{
char class_code[7];
char *name;
};
char buffer[101];
struct unit units[1000];
scanf("%s", buffer);
units[0].name = (char *) malloc(strlen(buffer)+1);
strcpy(units[0].name, buffer);