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 8771069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:41:41+00:00 2026-06-13T17:41:41+00:00

After opening a file in append update mode, is it necessary to execute a

  • 0

After opening a file in append update mode, is it necessary to execute a file positioning statement before each write to the file?

FILE *h;
int ch;
if ((h = fopen("data", "a+")) == NULL) exit(1);
if (fseek(h, 0 SEEK_SET)) exit(2);
ch = fgetc(h); /* read very first character */
if (ch == EOF) exit(3);

/* redundant? mandatory? */
fseek(h, 0, SEEK_END); /* call file positioning before output */

/* add 1st character to the end of file on a single line*/
fprintf(h, "%c\n", ch);

The C11 Standard says:

7.21.5.3/6 … all subsequent writes to the file to be forced to the then current end-of-file …

and

7.21.5.3/7 … input shall not be directly followed by output without an
intervening call to a file positioning function …

I take it the shall in 7.21.5.3/7 is stronger than the description in 7.21.5.3/6.

  • 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-13T17:41:42+00:00Added an answer on June 13, 2026 at 5:41 pm

    Probably not redundant in portable C. While the underlying file descriptor will always append (at least on Unix), the point of the fseek/fflush requirement is to get rid of the input buffer before writing to the output, so that the same buffer can be used for reading and writing. AFAIK you’re not even required to seek to end of file, you can seek anywhere, as long as you seek.

    The second description is stronger than the first, but that is to be expected. The first only states that all writes go to EOF, i.e. that there’s no way to write anywhere else. The second establishes the rule that switching from reading to writing must be accompanied by a flush or seek, to ensure that read and write aspects of the buffer don’t get mixed up.

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

Sidebar

Related Questions

After opening a file for writing: FILE *file = fopen(./file, w); Can I assume
After opening a file created by root in vim , how to change the
I'm opening lots of files with fopen() in VC++ but after a while it
I want to reach parts of a large file randomly. After opening the part
I am trying to write a file and append data to it. Here is
I've never compiled before on OS X or using g++, but after opening my
After opening the file descriptor fd and other sanity checks for /dev/random, I am
I want to be aware of the particular file was opened. After opening the
i got a program that send file to mobile device. After opening it in
print() doesn't work in IE after opening a new window. It works in Chrome.

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.