how to readline?

Post here if you don't find any other place for your post. But please, stay on-topic: algorithms, programming or something related to this web site and its services.

Moderator: Board moderators

Post Reply
Lingyis
New poster
Posts: 4
Joined: Sat Nov 18, 2006 8:41 am

how to readline?

Post by Lingyis » Mon Dec 04, 2006 11:46 pm

Hi,
Is there a simple library function I can use to read a single line from stdin in 1) C and 2) C++? Thanks in advance.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Tue Dec 05, 2006 12:00 am

1)

Code: Select all

char buffer[maximum_size_of_input_line_you_expect + 1];
gets(buffer);
2)

Code: Select all

string s;
getline(cin, s);

ebrahim
New poster
Posts: 6
Joined: Fri Jan 05, 2007 2:08 am
Contact:

Post by ebrahim » Sat Jan 06, 2007 7:04 pm

Using the magic of scanf:

Code: Select all

char line[MAX_LINE_LENGTH+1];
scanf("%.*[^\n]", MAX_LINE_LENGTH, line);

Post Reply

Return to “Other words”