Getting Started With C

Random access to files in C involves positioning the file pointer at a specific location within a file and performing read or write operations from that point. The fseek and ftell functions are commonly used for random access.

  • Examples :

    Program.c


  • In this example:

    - The writeToPosition function writes data to a file at a specific position, given by the position parameter.
    - The readFromPosition function reads data from a file at a specific position, given by the position parameter and reads size bytes.
    Note: The SEEK_SET constant is used with fseek to set the file position relative to the beginning of the file. Other constants like SEEK_CUR and SEEK_END can be used for different positioning methods.

    Resources :

    Test Your Knowledge
    Choose The

    With supporting text below as a natural lead-in to additional content.

    Q1. In C programming, which function is used to move the file position indicator to a specified location in a file?

    Q2. If you want to read a block of data from a file at a specific location in C, which function should you use?