how do I count the lines in a text file?
Hi folks,
how would I count the lines in a file?
I want to get a new unique ID# for a simple DB by counting the records and assigning this number + 1 for each new record.
The lines in the .txt file are as follows
<TABLE><TABLE BORDER><TH> ID#<TH> FIRST NAME<TH> LAST NAME<TH> TEST 1 <TR>
<tr><td>0<td>donkey<td><td>derby<td><td>12<tr>
I have tried this but it doesn't work
FILE *r ;
r = fopen(datafile,"a"); // I'll error check later if
//I get this bit to work first
while((inchar=fgetc(r))!=EOF){
if(inchar == '\n')
linecount++ ;
}
linecount remains at 0 (the swine)
The function which printed the file is
fprintf(r,"%s%s%s%s%s%s%s%s\n",b,d,g,f,h,i,c,j);
so there is a \n in there to be counted.
I have tried numerous other ways from the C board archives
but nothing works!
what am I doing wrong?
any help would be greatly appreciated.