You need to do a second allocation for the name
member:
#define MAX_INPUT_LENGTH 20 // or however long your input needs to be
...
/**
* Allocate space for the struct instance.
*/
invent *one = malloc( sizeof *one );
if ( !one )
{
fprintf( stderr, "memory allocation for one failed, exiting...\n" );
exit( EXIT_FAILURE );
}
/**
* At this point, one->name is uninitialized and doesn't point anywhere
* meaningful. Perform a second allocation to set aside space for the
* input string itself. Remember to account for the string terminator.
*/
one->name = malloc( sizeof *one->name * (MAX_INPUT_LENGTH + 1) );
if ( !one->name )
{
fprintf( stderr, "memory allocation for one->name failed, exiting...\n" );
exit( EXIT_FAILURE );
}
/**
* At this point, we can store a string in one->name
*/
scanf( "%s", one->name );
When you're finished, you deallocate in the reverse order you allocated:
free( one->name );
free( one );