-1
#include<stdio.h>

int main()
{
    char firstname[40];
    char lastname[40];
    printf("what's your name? \n");
    scanf(" %s %s ", firstname, lastname);
    printf("hello there %s %s \n", firstname, lastname);
    return 0;
}

the program freezes after scanning firstname and lastname

1 Answers1

2

The trailing space in your format string is consuming any whitespace after you enter the first and last names, which includes newlines. This means you would need to enter some non-whitespace after the first and last name before scanf returns.

Get rid of the spaces on either end of the format string.

scanf("%s %s", firstname, lastname);
dbush
  • 205,898
  • 23
  • 218
  • 273