CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    116

    File Reading Help

    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?

    Sample file content:
    Time_Stamp Value
    20110129 18:21:12 01
    20110129 18:40:59 02
    20110129 18:47:01 02

    20110129 18:59:06 02
    20110129 19:05:09 02

    Sample code:
    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);
    			sscanf (inLine, "%s %s", rDate, rTime );
    
    		}
    	}
    
    	return 0;
    }
    See attached image for more info.

    Hope you all can advise.
    Attached Images Attached Images
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured