J
jaswinder
I have a program which writes in the date and time into a txt file
everytime I
turn on my computer.
Ex:
Tue 08-03-2010 4:27:21.81p
Wed 08-04-2010 4:19:29.12p
Thu 08-05-2010 6:17:31.65p
Fri 08-06-2010 3:10:21.59p
Fri 08-06-2010 4:42:51.31p
I would like to make a program that counts each line and after it counts
all
the lines in the txt file it should tell me the total number of boots I
made to
date.
Here is what I have so far.
#include<stdio.h> // needed for IO functions
main()
{
int strlen(); // in strings.h but save time reading whole header
int lc=0; // define lc to be an int initialized to 0 (line count)
FILE *f; // pointer to a FILE (log.txt)
char bfr[96+1]; // string buffer w/ NULL terminater
char *bfrptr=&bfr[0]; // pointer to string buffer
f=fopen("log.txt","rb"); // setup FILE
do{
bfrptr=fgets(bfrptr,96,f); // pull a line from the file
if(strlen(bfr)>0) ++lc; // ignore empty lines
}while(!feof(f)); // stop at end of file
printf("Welcome you are entering OS from the %d time!\n",lc); //
display message
}
Any suggestion would be nice! A wrong answer is given.
Thank You.
everytime I
turn on my computer.
Ex:
Tue 08-03-2010 4:27:21.81p
Wed 08-04-2010 4:19:29.12p
Thu 08-05-2010 6:17:31.65p
Fri 08-06-2010 3:10:21.59p
Fri 08-06-2010 4:42:51.31p
I would like to make a program that counts each line and after it counts
all
the lines in the txt file it should tell me the total number of boots I
made to
date.
Here is what I have so far.
#include<stdio.h> // needed for IO functions
main()
{
int strlen(); // in strings.h but save time reading whole header
int lc=0; // define lc to be an int initialized to 0 (line count)
FILE *f; // pointer to a FILE (log.txt)
char bfr[96+1]; // string buffer w/ NULL terminater
char *bfrptr=&bfr[0]; // pointer to string buffer
f=fopen("log.txt","rb"); // setup FILE
do{
bfrptr=fgets(bfrptr,96,f); // pull a line from the file
if(strlen(bfr)>0) ++lc; // ignore empty lines
}while(!feof(f)); // stop at end of file
printf("Welcome you are entering OS from the %d time!\n",lc); //
display message
}
Any suggestion would be nice! A wrong answer is given.
Thank You.