Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > fgets and newline

Reply
Thread Tools

fgets and newline

 
 
Mike Mimic
Guest
Posts: n/a
 
      05-15-2004
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
 
Reply With Quote
 
 
 
 
Jacques Labuschagne
Guest
Posts: n/a
 
      05-15-2004
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.
 
Reply With Quote
 
 
 
 
Mike Mimic
Guest
Posts: n/a
 
      05-15-2004
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
 
Reply With Quote
 
Jacques Labuschagne
Guest
Posts: n/a
 
      05-15-2004
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
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      05-15-2004

"Mike Mimic" <(E-Mail Removed)> wrote in message
news:c83o1a$h27$(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
removing newline character from the buffer read by fgets junky_fellow@yahoo.co.in C Programming 16 11-28-2006 10:44 PM
seek and fgets and fputs fopen dave C++ 4 11-02-2006 10:10 PM
ow can i use fgets to read and ignore the first two lines of a file and output into another file Justme C Programming 9 10-01-2006 02:26 PM
on fgets and sscanf and their bugs RSoIsCaIrLiIoA C Programming 7 04-25-2006 06:42 PM
fscanf or fgets still misses last line unless there is a newline Charles Erwin C Programming 4 10-06-2003 08:12 PM



Advertisments