My objective is to store the desired date and time.
In this case, I wish to stop reading when encounter the next blank line. Meaning I only wish to store the date and time - 20110129 18:47:01.
However, by using code below I will get the latest time stamp - 20110129 19:05:09 02.
Is there any better way to break from the while loop when encounter the blank line in between?
You aren't even attempting to check for the blank line in your code, so what do you expect?
I'd say one easy way to check for that condition is checking the value returned by sscanf(). It returns the number of fields it successfully parsed which will be 2 for the lines actually containing a timestamp. The return value will be something else for the blank line.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
I would like to add that you are not processing the first line at all.
Also, you are not using feof() correctly: EOF condition is not set until AFTER you attempt to read past the end of file.
It’s better (easier AND correct) to simply check return value of fgets():
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
I would like to add that you are not processing the first line at all.
I initially wondered about that too, but it's because the first line of the input file contains the column headers.
Also, you are not using feof() correctly: EOF condition is not set until AFTER you attempt to read past the end of file.
It’s better (easier AND correct) to simply check return value of fgets():
Oh, yes. However, the posted code in conjunction with the attached demo input file doesn't expose apparent problems resulting from that because the demo file's last line is lacking the line terminator. It probably would not work if it had one. OTOH, that way the code you posted would probably ignore the last line of that particular file, but that's just exposition of the faulty format of the input file...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.