🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #732

Re: question about get_line implementation.

#732
From: Dennis Swanson
Date: Sat, 05 Sep 1998 00:00
43 lines
2771 bytes
Who would have guessed that on Sat, 29 Aug 1998 at 03:17:56 +0800
Centaury (utopian@hehe.com) would say:
~ I need to implement a get_line routine. It should get ONE line from an input
~ text file and return all characters as a pointer variable.
~ 
~ And here are my considerations and trials:
~ 
~ detect '\n' as the end-of-line character for the routine to return.
~ 
~ After testing with a driver, I found out that it did the job, but it returns
~ extra funny characters which are always the same character type. I suspect
~ that it is CR or FF. Can anyone confirm this? If that is the case, how

DOS/Windows text files have lines ending in CR and then LF.

~ should I logically combine '\r' with '\n' as a testing condition in the
~ while loop?

I would check for either one, as _maybe_ you'll someday run across a text
file from a UNIX box or a Mac that has lines ending in only LF or CR,
respectively. When you find one, check to see if the other's present
(just so it's not the first char in the next line read).

~ One more question: does the current cursor position of a file persist
~ througout the file's open lifetime, regardless of where it's scope is??

I don't think there's a _the_ current cursor position of a file. I think
each time you open a file, a data structure (either owned by the OS or
the C RTL or whatever) is initialized, and one of the pieces of data
held in each is a current file position for that instance. Regarding
scope, note that if you're using file iostreams in C++, where the file
is opened as a result of the constructor being called (as a result of
declaring a new object), when the object goes out of scope, its destructor
is automatically called by the compiler, closing that file, freeing any
data structure the system had associated with it, including the current
file position for that particular point of access.

	Den

-- 
Dennis M. Swanson     <><     C/Win32 API programmer     UNIX hobbyist

                What if you were a vegetarian cannibal?
Technical Details
Message-ID: <swansondEysqI0.4H7@netcom.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35e70268.0@news2>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114592,11de81bc1593f087
X-Google-Attributes: gid114592,public
X-Google-Thread: 1014db,11de81bc1593f087
X-Google-Attributes: gid1014db,public
X-Google-Thread: 10f67c,11de81bc1593f087
X-Google-Attributes: gid10f67c,public
X-Google-Thread: 106434,11de81bc1593f087
X-Google-Attributes: gid106434,public
From: swansond@netcom.com (Dennis Swanson)
Subject: Re: question about get_line implementation.
Date: 1998/09/05
Message-ID: <swansondEysqI0.4H7@netcom.com>
X-Deja-AN: 388077438
Sender: swansond@netcom16.netcom.com
References: <35e70268.0@news2>
Organization: Who wants to know?
Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c,fj.lang.c,it.comp.lang.c