Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8574531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:29:42+00:00 2026-06-11T19:29:42+00:00

Please correct the below code:only. file already contains entries : 1st row username; 2nd

  • 0

Please correct the below code:only.

file already contains entries : 1st row username; 2nd row password.

checkbox status required to write to the third line and need to read or alter only the checkbox status value in the file.

Currently this code is working if there already is a value for the checkbox status value, then it is overwriting, else UI is hanging.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:29:43+00:00Added an answer on June 11, 2026 at 7:29 pm

    This line

    fprintf(l_pFile, sVar);
    

    doesn’t look right. I think it should be

    fprintf(l_pFile, "%s\n", (LPCTSTR) sVar);
    

    The loop could become infinite if the file has less than two linefeeds:

    while(count != 2)
    

    I think it should be:

    while( (count < 2) && ( ! feof(l_pFile) ) && ( c != EOF ) )
    

    Probably unrelated to your error, but – at least for this code snippet – CString::ReleaseBuffer() doesn’t need to be called since you have not called CString::GetBuffer().

    l_strRememberCheck.ReleaseBuffer();
    

    This line may be unnecessary as it appears to fseek() to where the file pointer already is:

    fseek(l_pFile,ftell(l_pFile),SEEK_SET);
    

    In the event a two-line file is not terminated with a ‘\n’ you would need to print like this:

       if ( count == 2 )
       {
          fprintf(l_pFile, "%s\n", (LPCTSTR) sVar);
       }
       else
       {
          fprintf(l_pFile, "\n%s\n", (LPCTSTR) sVar);
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could you please correct my code below. #!/usr/local/bin/perl open (MYFILE, '>>data.xml'); print MYFILE <?xml
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
Please help me with php file that must redirect to correct language. the site
Could you please explain why this code is not syntactically correct? private void addEditor(final
I'm trying to find out why this entire code below is producing only ONE
Below is my code where the user can upload a file. What I want
Hi all please give a look to this code in my properties file i
hey guys, i have very small issue please see the code below // this
Please correct me if I am wrong, but is one complex query less expensive
please correct the program. Q. Write a java prg to accept RollNo, Name of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.