Here is what I did with your code. I left a note when there was error checking to be done. I did not resize the struct, but it is similiar to how I did the char* dave.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct stuff {
char *dave, *temp_dave;
int steve;
};
int main(void) {
struct stuff *mate = NULL;
mate = malloc(sizeof(struct stuff));
mate->dave = malloc(sizeof(char)*16);
strcpy(mate->dave, "Dave");
printf("%s\n", mate->dave);
mate->temp_dave = realloc(mate->dave, sizeof(char)*32);
// Error check
mate->dave = mate->temp_dave;
printf("%s\n", mate->dave);
free(mate->dave);
return 0;
}
Notice that you need to make the char* bigger then just sizeof(char). That is because you want it to hold several char's, not just one. In this case I used 16, but you can change it to any number.
- Sean