Greg Bacon wrote: > > In message <[EMAIL PROTECTED]>, > Greg Bacon writes: > > : Yesterday, I saw an interesting related exercise. Write a program that > : reads the lines from a file and outputs the middle line. The kicker is > : that you can't use arrays. (Note that there's a little ambiguity with > : respect to the definition of "middle line" when the number of lines in > : the file is even or when there is only one line. Just pick a reasonable > : definition and get to work.) > > Sorry, I wasn't clear on an important point. You only get one pass > through the file. > > Greg
then there is no solution! in any case you have to count number of newlines so you have to either save data to memory or scan file and get back to the middle... going back to the middle point is actually `second pass' and does not count! doing some cheap tricks with tell/seek requires to save newlines locations which as I said is `second pass' really (even don't mention that you need memory to save those locations) finally if you add and something like: `it should work on a stream, i.e. filter' then we need a magic for this :))) even it the latest case there is simple memory solution if you tell if using arrays is equal to using memory (even external like second file which will pass the rules but will take extra disk space;))... P! Vladi. -- Vladi Belperchinov-Shabanski <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> Personal home page at http://www.biscom.net/~cade DataMax Ltd. http://www.datamax.bg Too many hopes and dreams won't see the light...
smime.p7s
Description: S/MIME Cryptographic Signature
