How do I read a whole line in C?

  • Thread starter Thread starter Whovian
  • Start date Start date
  • Tags Tags
    Line
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
Whovian
Messages
651
Reaction score
3
Code:
#include <stdio.h>

int main()
{
    char name[256];
    printf("What's your name?\n");
    scanf("%s",name);
    printf("Hello, %s%s",name,"!");
}

This only reads the first word of the name inputted. Is there any way to get a whole line?
 
Physics news on Phys.org