void readLine()
{
FILE *fpTest;
fpTest = fopen ( "test.txt", "r" );
int countRead = 0,countLine = 0,countCodeDataLine = 0,length = 0;
if(fpTest ==NULL){
printf("error in opening test.txt file" ); // perror
exit(0);
}
while( !feof(fpTest) )
{
fgets ( line, MAXATTRLINELEN, fpTest );
countRead++;
length = strlen(line);
printf("[%d]:%s(lineLength=%d) \n",countLine,line,length);
if(length > 0)
{
countLine++;
}
// count countCodeDataLine
if(length == 0) ;
else if(length ==1)
{
//printf(" %d %d %d %d %d",line[0], '\n', '\r' , '\r\n', '\n\r');
if(line[0]==' ' || line[0] == '\n' || line[0] == '\t' ) ;
else
countCodeDataLine++;
}else
{
countCodeDataLine++;
}
line[0] = '\0';
}
printf(" Read %d . Line %d . Dataline %d\n",countRead, countLine,countCodeDataLine);
fclose ( fpTest );
}
Comments
Post a Comment