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

fgets and newline

P: n/a
Hi!

Is there a way to "say" to fgets to use any of \n, \r, \r\n end line
markers as line separators?

Is there some other library function which would read line by line (end
line markers do not need to be included).
Mike
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mike Mimic wrote:
Hi!

Is there a way to "say" to fgets to use any of \n, \r, \r\n end line
markers as line separators?

Is there some other library function which would read line by line (end
line markers do not need to be included).
Mike


std::getline?
Jacques.
Jul 22 '05 #2

P: n/a
Hi!

Jacques Labuschagne wrote:
Mike Mimic wrote:
Is there a way to "say" to fgets to use any of \n, \r, \r\n end line
markers as line separators?

Is there some other library function which would read line by line
(end line markers do not need to be included).


std::getline?


I missed that.

But if line is terminated with \r\n that I will have to call getline
twice for every line as I will get empty line after \r.

And how can I convert file descriptor to a C++ stream (as fdopen)?
Mike
Jul 22 '05 #3

P: n/a
Mike Mimic wrote:

I missed that.

But if line is terminated with \r\n that I will have to call getline
twice for every line as I will get empty line after \r.
Not if you use \n as your delimiter and just erase the \r by hand.
Something like:

getline(myfile, mystring, '\n');
if (*mystring.rbegin() == '\r'){
*mystring.rbegin() = ' ';
// or you could actually call mystring.erase()
}

And how can I convert file descriptor to a C++ stream (as fdopen)?


fdopen() is not part of standard C or C++. If you're doing platform
specific stuff you may need to write your own getline() equivalent.
Jacques
Jul 22 '05 #4

P: n/a

"Mike Mimic" <pp****@yahoo.com> wrote in message
news:c8**********@planja.arnes.si...
Hi!

Is there a way to "say" to fgets to use any of \n, \r, \r\n end line
markers as line separators?
No, write your own function to do this. Simple enough I think.

Is there some other library function which would read line by line (end
line markers do not need to be included).


std::getline, but again doesn't do the processing on end of lines you
require.

john
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.