read the i/p file count the no. of '\n' characters if count > k (argument of tail) then print all chars till EOF
correct me if m wrong !!! On Aug 16, 9:16 am, vikas kumar <vikas.kumar...@gmail.com> wrote: > the method of farword seek is inefficient. consider case of 100000 > lines and you want to display only 3-4 lines. better seek from end. > > se a buffer[buf_size]. > > let size =filesize. > lc = 0; > while(lc <= given line input) > { > fseek(fp, size); > if(size < buf_size) > fread(fp, size, buffer); > else > fread(fp, size, buf_size); > > parse buf_size for '\n' > if( \n is in buffer ) > increment line counter(lc ++) > if(size < buf_size) > size -= buf_size > > } > > // you know the size, read the buffer one by one and print it > OR > // you could have put them while reading on to stack and print it out > now > > On Aug 15, 8:46 am, Dave <dave_and_da...@juno.com> wrote: > > > > > Enter the lines into a FIFO queue as you read them. After you have > > enqueued n lines, dequeue a line every time you enqueue one, so that > > the queue will contain the last n (or fewer) lines of the file. > > > Dave > > > On Aug 13, 1:13 pm, amit <amitjaspal...@gmail.com> wrote: > > > > I am trying using fseek but somehow its not working?- Hide quoted text - > > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.