Which of the following functions changes the position of file pointer andreturns its new position?
Question
Which of the following functions changes the position of file pointer and returns its new position?
Solution
The function that changes the position of the file pointer and returns its new position is the fseek() function in C programming. Here's how it works:
-
The fseek() function is declared in the stdio.h header file. It is used to move the file pointer to a specific location in the file.
-
The syntax of the fseek() function is as follows:
int fseek(FILE *pointer, long int offset, int position);
-
The 'pointer' is the pointer to the file where the file pointer needs to be moved.
-
The 'offset' is the number of characters to move the file pointer. If the offset is negative, the file pointer moves to the backward direction.
-
The 'position' is the starting point where the file pointer to be moved. It has three values:
- SEEK_SET: It denotes the beginning of the file.
- SEEK_CUR: It denotes the current position of the file pointer.
- SEEK_END: It denotes the end of the file.
-
The fseek() function returns zero if the operation is successful. If the operation fails, it returns a non-zero value.
-
After the fseek() function is called, you can use the ftell() function to get the current position of the file pointer. The ftell() function returns the current position of the file pointer.
Similar Questions
_______________________ resides within the file and moves with the file, not changing unless the contents of the file are altered.
Which of the following operations can be performed on the file "NOTES.TXT" using the below code?FILE *fp;fp = fopen("NOTES.TXT", "r+");
If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
What does fp point to in the program ?#include<stdio.h>int main(){FILE *fp;fp=fopen("trial", "r");return 0;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.