Humanities/Arts Exam  >  Humanities/Arts Questions  >  Which set of functions can be used to read or... Start Learning for Free
Which set of functions can be used to read or write a file randomly?
  • a)
    fseek(), getc(), ftell()
  • b)
    fseek(), putc(), ftell()
  • c)
    fseek(), rewind(), getc()
  • d)
    fseek(), rewind(), ftell()
Correct answer is option 'D'. Can you explain this answer?
Most Upvoted Answer
Which set of functions can be used to read or write a file randomly?a)...
To access only a particular part of a file, functions such as fseek(), rewind(), and ftell() can be used.
Free Test
Community Answer
Which set of functions can be used to read or write a file randomly?a)...
Reading and Writing a File Randomly

To read or write a file randomly, we need to be able to navigate to specific positions within the file. This requires the use of certain functions that allow us to manipulate the file pointer. The correct set of functions that can be used for this purpose is option 'D': fseek(), rewind(), and ftell().

Explanation:
Let's understand each function and its role in reading or writing a file randomly.

1. fseek()
- The fseek() function is used to move the file pointer to a specific position within the file.
- It allows us to perform random access on a file by specifying the offset (number of bytes) to move from a given reference position.
- The function prototype for fseek() is: `int fseek(FILE *stream, long int offset, int origin);`
- stream: Pointer to the file stream.
- offset: Number of bytes to move the file pointer.
- origin: Reference position from where the offset is calculated (e.g., SEEK_SET, SEEK_CUR, SEEK_END).

2. rewind()
- The rewind() function is used to move the file pointer to the beginning of the file.
- It sets the file position indicator to the start of the file, allowing us to read or write from the beginning.
- The function prototype for rewind() is: `void rewind(FILE *stream);`
- stream: Pointer to the file stream.

3. ftell()
- The ftell() function is used to determine the current position of the file pointer within the file.
- It returns the current value of the file position indicator, which represents the number of bytes from the beginning of the file.
- The function prototype for ftell() is: `long int ftell(FILE *stream);`
- stream: Pointer to the file stream.

Combining the Functions:
To read or write a file randomly, we can use a combination of these functions as follows:

1. Use fseek() to move the file pointer to the desired position within the file.
- This can be done by calculating the offset from a reference position using the fseek() function.

2. Perform the desired read or write operation at the current position of the file pointer.

3. To move back to a specific position for further random access within the file:
- Use fseek() to move the file pointer to the desired position.
- Use ftell() to retrieve the current position of the file pointer for reference.

4. To move back to the beginning of the file for a fresh random access:
- Use rewind() to set the file position indicator to the start of the file.

By using fseek(), rewind(), and ftell() in combination, we can read or write a file randomly by navigating to specific positions within the file. This allows us to access data in any order, rather than just sequentially.
Explore Courses for Humanities/Arts exam

Top Courses for Humanities/Arts

Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer?
Question Description
Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer? for Humanities/Arts 2024 is part of Humanities/Arts preparation. The Question and answers have been prepared according to the Humanities/Arts exam syllabus. Information about Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for Humanities/Arts 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer?.
Solutions for Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Humanities/Arts. Download more important topics, notes, lectures and mock test series for Humanities/Arts Exam by signing up for free.
Here you can find the meaning of Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Which set of functions can be used to read or write a file randomly?a)fseek(), getc(), ftell()b)fseek(), putc(), ftell()c)fseek(), rewind(), getc()d)fseek(), rewind(), ftell()Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice Humanities/Arts tests.
Explore Courses for Humanities/Arts exam

Top Courses for Humanities/Arts

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev