say something like this:
#include <stdio.h>
void main() {
char fname[30];
char lname[30];
printf("Type first name:\n");
scanf("%s", fname);
printf("Type last name:\n");
scanf("%s", lname);
printf("Your name is: %s %s\n", fname, lname);
}
if i type "asdas asdasdasd" for fname, it won’t ask me to input something for lname anymore. I just want to ask how i could fix this, thank you.
Use
fgets(orgetlineif you are using GNU) to get an entire line instead of until the first whitespace.See it working online: ideone
You could also consider using the function
fgets_wrapperfrom this answer as it will also remove the new line character for you.