Hello,
gcc c89
I am getting a stack dump on this line:
strcpy(comp->persons->name, "Joe");
However, I have allocated memory, so not sure why I would be getting it. Am I missing something here?
Many thanks for any advice,
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct company
{
struct emp *persons;
char company_name[32];
};
struct emp
{
char name[32];
char position[32];
};
int main(void)
{
struct company *comp;
comp = malloc(sizeof *comp);
memset(comp, 0, sizeof *comp);
strcpy(comp->persons->name, "Joe");
strcpy(comp->persons->position, "Software Engineer");
printf("Company = [ %s ]\n", comp->company_name);
printf("Name ==== [ %s ]\n", comp->persons->name);
printf("Postion ==== [ %s ]\n", comp->persons->position);
free(comp);
return 0;
}