name is only an unallocated pointer so scanf("%s",name); will do no more than crash your program pretty hard. scanf() does not allocate the space, you have to do that yourself before calling that function
Code:
char name[255];
scanf("%s",name);
or more safely because it does not accept more characters
from the keyboard that can be put into the buffer.
fgets(name,sizeof(name),stdin);
The problem with fgets() is that it appends newline '\n' at the end
Code:
fgets(name,sizeof(name),stdin);
name[strlen(name)-1] = 0; // delete '\n'
in C it is not necessary to typecast the return value of any function that returns void*, like malloc(). And you forgot to add 1 more byte for the string's null terminator. No need for sizeof(char) because sizeof(char) is ALWAYS == 1.
Code:
char *copy = malloc(strlen(name)+1);
Code:
strcpy(names,copy);
why ^^^^ ??? delete that line.
finally -- the function is supposed to return the pointer ? Then make the return type char*, not void
Code:
char* addName(void)
{
...
return copy;
}