You are here:

C/Read line whole line from the console in linux

Advertisement


Question
Hi Sir:

I was trying to read a line from the standard in put console with the string limited by the length parameter. I have predefined skeleton of the function void getline(char *buf, size_t len), so here i have to read line of string into buf but when i enter string which is greater then len, next time i call function it seems it automatically takes the string from 10 to end of the string which i entered before and is unwanted , i tried flushing buffer by the fflush(stdin) but still its not working, can you please tell me another method of dong that?

Answer
Dear Dipen

Thank you for explaining the problem so well, but in order for me to be able to help you, I would need the code that you are working with. Kindly send me the code and I will be able to tell you how we can get what you want.

Warm Regards
Smitha Renny

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Smitha Renny

Expertise

I can answer questions related to basic understanding of C concepts, arrays, pointers and their handling well.

Experience

I've been programming in BASIC since 1987. Later moved onto Pascal for a short period and then hooked onto C since 1997.

Education/Credentials
I have completed a Post-Graduate diploma in Computer Applications. Currently doing MCA

©2012 About.com, a part of The New York Times Company. All rights reserved.