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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:16:09+00:00 2026-06-14T12:16:09+00:00

I know that the function fseek() can be used to output data to a

  • 0

I know that the function fseek() can be used to output data to a specific location in a file. But I was wondering if I use fseek() to move to the middle of the file and then output data. Would the new data overwrite the old data? For example if I had a file containing 123456789 and I used fseek() to output newdata after the 5 would the file contain 12345newdata6789 or would it contain 12345newdata.

  • 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-14T12:16:10+00:00Added an answer on June 14, 2026 at 12:16 pm

    Yes it lets you do that, and those files are called “Random Access Files”. Imagine you have already a set file ( with the structure but empty ), in that case you can fill the “slots” you want, or in the case the slot is filled with data you can overwrite on it.

    typedef struct{
        int number;
        char name[ 20 ];
        char lastname[ 20 ];
        float score;
    }students_t;
    
    /* Supposing that you formatted the file already and the file is opened. */
    /* Imagine the students are listed each one has a record. */
    
    void modifyScore( FILE * fPtr ){
        students_t student = { 0, "", "", 0.0 };
        int nrecord;
        float nscore;
    
        printf( "Enter the number of the student:" );
        scanf( "%d", &record )
        printf( "Enter the new Score:" );
        scanf( "%f", &nscore ); // this is a seek example so I will not complicate things.
    
        /*Seek the file ( record - 1 ), because the file starts in position 0 but the list starts in 1*/
        fseek( fPtr, ( record  - 1  ) * sizeof ( students_t ), SEEK_SET );
    
        /* Now you can read and copy the slot */
        fread( fPtr, "%d%s%s%f", &student.number, student.name, student.lastname, &student.score );
    
        /* Seek again cause the pointer moved. */
        fseek( fPtr, ( record  - 1  ) * sizeof ( students_t ), SEEK_SET );
        student.score = nscore;
    
        /*Overwrite his information, only the score will be altered. */
        fwrite( &student, sizeof( student_t ), 1, fPtr );
    }
    

    This is how it works (picture obtained from Deitel-How to program in C 6th Edition):

    Deitel-How to program in C 6th Edition

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

Sidebar

Related Questions

I know that when you define a function in vim, you can use the
I know that when you define a function in vim, you can use the
I know that when passing an object by value to a function, the move
Is there such a thing? I know that I can hook my function on
I do know that include guards are to prevent redefinition. But does function prototype
I know that function arguments are padded to target word size, but with what?
I do know that in javascript, when you use this keyword inside a function,
I know that ISKINDOF() function is used to compare two class objects that is
I know that Java doesn't really use exact pass by reference, but rather pass
I know that Function Templates are used so as to make the functions portable

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.