You may have allocated memory for your struct, but not for its character pointer.
You can't perform a strcpy onto memory that isn't allocated. You could say
s->name = "Hello World";
instead.
Alternatively, allocate memory for your char, and then perform the copying.
NOTE: I in NO way endorse that the following code is good, just that it will work.
int main()
{
struct example *s = malloc(MAX);
s->name = malloc(MAX);
strcpy(s->name ,"Hello World!!");
return !printf("%s\n", s->name);
}
Edit: Here is perhaps a cleaner implementation, but I still hate C-style strings
#include
#include
#include
#define KNOWN_GOOD_BUFFER_SIZE 64
typedef struct example {
char *name;
} MyExample;
int main()
{
MyExample *s = (MyExample*) malloc( sizeof(MyExample) );
s->name = (char*) malloc(KNOWN_GOOD_BUFFER_SIZE);
strcpy(s->name ,"Hello World!!");
printf("%s\n", s->name);
free(s->name);
free(s);
return 0;
}