Using the following code:
char *name = malloc(sizeof(char) + 256); printf(\"What is your name? \"); scanf(\"%s\", name); printf(\"Hello %s. Nice to meet y
You can use this
char name[20]; scanf("%20[^\n]", name);
Or this
void getText(char *message, char *variable, int size){ printf("\n %s: ", message); fgets(variable, sizeof(char) * size, stdin); sscanf(variable, "%[^\n]", variable); } char name[20]; getText("Your name", name, 20);
DEMO