Newsgroup: it.comp.lang.c
Titolo: question about get_line implementation.

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
should I logically combine '\r' with '\n' as a testing condition in the
while loop?
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??
Thanks a million, and please send replies/comments to:
uto...@hehe.com

 writes:
   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
   should I logically combine '\r' with '\n' as a testing condition in the
   while loop?
The character is probably EOF.  Show us your code.
-- 
(supporter of the campaign for grumpiness where grumpiness is due in c.l.c)
Please: do not email me copies of your posts to comp.lang.c
        do not ask me C questions via email; post them instead

Who would have guessed that on Sat, 29 Aug 1998 at 03:17:56 +0800
Centaury (
uto...@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?