Re: [algogeeks] MS Question:WAP to print last n lines of a log file
lines = 0; string last_n_lines[n]; //read each line into a circular buffer while(getline(file,last_n_lines[lines%n])) { lines++; } // if number of lines n // then print all of them if(lines=n) { start = 0; count = lines; } else { start = lines%n; count = lines; } //Now print all of them. for(i=0;icount;i++) { coutlast_n_lines[(start+i)%n]; } For example if we have n = 4 and lines = 7 after reading we have 5,6,7 and 4 th lines in array last_n_lines; start = lines%n=3, So, we print 4, 5, 6 and 7 lines -- With love and regards, Sairam Ravu I M.Tech(CS) Sri Sathya Sai Institute of Higher Learning To live life, you must think it, measure it, experiment with it, dance it, paint it, draw it, and calculate it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] MS Question:WAP to print last n lines of a log file
Read line by line . use doublylinkedlist(Queue)/ Circular Buffer of size N. when EOF is achieved print the lines. On Mon, Mar 4, 2013 at 9:10 AM, Ashish Goel ashg...@gmail.com wrote: Q1. Given a log file, pirnt last n lines. Note that the Log file is being written into. Q2. Implement Circular Buffer. Best Regards Ashish Goel Think positive and find fuel in failure -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- Regards, Sourabh Kumar Jain +91-8971547841 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] MS Question:WAP to print last n lines of a log file
Both questions look related to me. If the log file is being updated as well simultaneously, you should be able to use Circular queue/buffer for that. On Mon, Mar 4, 2013 at 9:10 AM, Ashish Goel ashg...@gmail.com wrote: Q1. Given a log file, pirnt last n lines. Note that the Log file is being written into. Q2. Implement Circular Buffer. Best Regards Ashish Goel Think positive and find fuel in failure -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [algogeeks] MS Question:WAP to print last n lines of a log file
int main() { int n=10; coutEnter the value of n:; cinn; int i=0; ifstream file(C:\\Users\\kvb\\Desktop\\sample.txt); string line; string buffer[n]; if(file.is_open()) { while(file.good()) { getline(file,line); buffer[i++%n]=line; } file.close(); } for(int j=i%n;jn;j++) { coutbuffer[j]endl; } for(int j=0;ji%n;j++) { coutbuffer[j]endl; } return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[algogeeks] MS Question:WAP to print last n lines of a log file
Q1. Given a log file, pirnt last n lines. Note that the Log file is being written into. Q2. Implement Circular Buffer. Best Regards Ashish Goel Think positive and find fuel in failure -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.