CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2012
    Posts
    21

    Read and write the values into file

    Hi!

    Please correct the below code:
    file already contains entries : 1st row username; 2nd row password.
    check status required to write at third line and need to read or alter the check status value.
    Currently this code is working if already there is a value for check status, then it is overwriting else UI hanging.


    Code:
    WriteCheckStatusToFile(BOOL& locVar)		
    {	
    	FILE *l_pFile = NULL;	
    	CString l_strRememberCheck;
    	l_strRememberCheck = GetExePath() + _T("password");
    	
    	CString sVar;
    	sVar.Format(_T("%d"),locVar);
    	if(NULL != (l_pFile = fopen(l_strRememberCheck, _T("r+"))) )
    	{
    		int count = 0;  
    		char c; 	 
    		while(count != 2) 
    		{   
    			if((c = fgetc(l_pFile)) == '\n') count++; 
    		} 		
    		fseek(l_pFile,ftell(l_pFile),SEEK_SET);   		
    		fprintf(l_pFile, sVar);
    	}
    	l_strRememberCheck.ReleaseBuffer();
    	fclose(l_pFile); 
    }

    thanks in advance to all!
    sam.
    Last edited by Marc G; October 1st, 2012 at 01:55 AM. Reason: Added code tags

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Read and write the values into file

    You should know about code tags by now.

    Since the loop runs while count != 2, and count is incremented only inside an if statement, clearly that if statement condition isn't met twice.

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Read and write the values into file

    [ removed duplicate thread ]
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Tags for this Thread

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