OPen a file and read it from the last line
Hi All
I am having a problem here. I have a file which saves the data as follows:
Thu 01/24/2008 8:59:27.42 - entry, aa_1, SYS_ADMIN
Thu 01/24/2008 9:01:45.02 - exit, aa_1, SYS_ADMIN
Thu 01/24/2008 9:02:28.69 - entry, aa_1, SYS_ADMIN
Thu 01/24/2008 9:02:45.21 - exit, aa_1, SYS_ADMIN
I want to open this file and read last row(the latest logged line), also i dont want to read the whole line all i am interested in is the word "SYS_ADMIN" in the latest logged row. How can i accomplish this in C Programming?...your help will highly be appreciated. I am pretty novice in C programming so your help will highly be regarded. Thanks in advance!
an alternative answer maybe
takes you to the end of file (as you already should know.)
you can use fgetc in a loop and increment the value of 0L to 1L 2L .... etc. and in every iteration you compare if it is "," . or if you already know the length of "SYS_ADMIN" you just do
fseek (fp, sizeof("SYS_ADMIN"), 2).
once you do that you can do as always with fgetc ...
by the way you should look at The GNU library reference manual. I am sure you will find something better. ;)