New Reply

How do I read a whole line in C?

 
Share Thread Thread Tools
May14-12, 03:29 PM   #1
 

How do I read a whole line in C?


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?
 
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> 'Whodunnit' of Irish potato famine solved
>> The mammoth's lament: Study shows how cosmic impact sparked devastating climate change
>> Curiosity Mars rover drills second rock target
May14-12, 03:45 PM   #2
 
Mentor
gets will read a whole line of text.
 
New Reply
Thread Tools


Similar Threads for: How do I read a whole line in C?
Thread Forum Replies
Fortran: Read data from a line in a file Programming & Comp Sci 1
Random walk question on 2D grid, probability of vertical line vs horizontal line hit Set Theory, Logic, Probability, Statistics 1
How to read this file line by line and store contents in an array Engineering, Comp Sci, & Technology Homework 2
How to read always from the first line when using READ in a loop? Programming & Comp Sci 1
Which Kurt Vonnegut books to read next? Or should I read Catch 22 instead? General Discussion 10