Possible Duplicate:
Dynamic String Input - using scanf(“%as”)
strcmp with pointers not working in C
Is the following considered good code? Shouldn't I have used malloc somewhere? I was able to compile this and it worked, but I feel like it shouldn't have.
#include <stdio.h>
int main (void) {
char *name;
printf("Whats your name? ");
scanf("%s", &name);
printf("\nyour name is %s", &name);
return 0;
}
What happens if I want to modify name? How would I go about doing so?
Edit: I am really just looking for the most efficient and correct way to do this using pointers. I am assuming malloc is necessary.