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

  • SEARCH
  • Home
  • 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 8744657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:52:35+00:00 2026-06-13T11:52:35+00:00

I need to read, and then write to a file. I don’t want to

  • 0

I need to read, and then write to a file. I don’t want to use “r+” because I completely overwrite it anyway. But I am unable to completely close the file. If I try to open the file for the second time, the applications crashes (can’t open). Does anyone know how to completely close the file.

And this is not the actually code, just a summary of what I want to do:

FILE* f;
fopen_s(&f, "test.txt", "r");
// read file and edit data
fclose(f);
f = 0;
fopen_s(&f, "test.txt", "w");
fprintf(f, "%c", data);
fclose(f);
  • 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-13T11:52:36+00:00Added an answer on June 13, 2026 at 11:52 am

    fclose() closes the file. It doesn’t half close it. The notion of “completely closing” a file doesn’t exist. A file is either open or closed. There’s no in-between.

    Although in your code you’re using fopen_s() to open the file. I’ve no idea what that function is. I assume it works like fopen(), but instead of returning a FILE pointer, it instead stores it in its argument.

    So the answer to your question is: to “completely” close a file, use fclose(). As you already do. That means the problem you’re having lies elsewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read in a file, then print it out to STDOUT but
I want to write in a file and then read from it. While using
I've used streamreader to read in a .csv file, then i need to split
I need to read the size of a file but the server is forcing
I need to write a function that can read a file, and add all
Within a VB.NET program, I want to read files from a filesystem, then write
I need to read in a string and then an integer until the user
I need to insert rows rows into a database, then in another thread read
I need to read test.TXT file(tab delimited) into MATLAB. TXT file have form: Datum
I need to read 16 bits from the binary file as std::string or char

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.