Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do I read a whole line in C?

  1. May 14, 2012 #1
    Code (Text):
    #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?
     
  2. jcsd
  3. May 14, 2012 #2

    Mark44

    Staff: Mentor

    gets will read a whole line of text.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook