There is no need to process the first line as it's the column header.
Thanks Eri523 and VladimirF for helping.
I guess I will change my code as follow so that it will stop reading when encounter blank line whereby sscanf return value is not 2.
Code:#include "stdafx.h" #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { char inLine[255]="", rDate[30]="", rTime[30]=""; FILE *fptr; if(( fptr = fopen( "TimeStamp.txt", "r" )) != NULL ) { fgets (inLine, 255, fptr); while (!feof (fptr)) { fgets (inLine, 255, fptr) ; if(sscanf (inLine, "%s %s", rDate, rTime )!=2) { printf("Encounter blank line!"); break; } } printf("Date=%s, Time=%s",rDate,rTime ); } return 0; }




Reply With Quote