By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

Read a line of unknown length in C

P: 9
Hi all,

In C, to read a line from a file, we need to allocate some fixed length of memory first. However, if the line is longer than the length of the allocated memory, it can't be read correctly.

Does anyone have codes that can read in a line of unknown length?

Thank you very much!
Jun 14 '07 #1
Share this Question
Share on Google+
1 Reply


Savage
Expert 100+
P: 1,764
Hi all,

In C, to read a line from a file, we need to allocate some fixed length of memory first. However, if the line is longer than the length of the allocated memory, it can't be read correctly.

Does anyone have codes that can read in a line of unknown length?

Thank you very much!
All you need is pointer to a char:

char *ptr.

and then you can parse the file using scanf functions.

See this article and especialy the part which tells about Non-buffered functions.

Savage
Jun 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.