Ocultar la entrada del usuario y solo permitir ciertos caracteres

¿Hay alguna forma de ocultar la entrada del usuario cuando se solicita en C? Por ejemplo

char *str = malloc(sizeof(char *));
printf("Enter something: ");
scanf("%s", str);getchar();
printf("\nYou entered: %s", str);

// This program would show you what you were writing something as you wrote it. 
// Is there any way to stop that?

Otra cosa, ¿cómo puedes permitir solo ciertos personajes? Por ejemplo

char c;
printf("Yes or No? (y/n): ");
scanf("%c", &c);getchar();
printf("\nYou entered: %c", c);

// No matter what the user inputs, it will show up, can you restrict that only 
// showing up if y or n are entered?

Respuestas a la pregunta(4)

Su respuesta a la pregunta