Rewind() function in C returns the file position indicator to the beginning of the file. It takes a file pointer as input and moves the indicator to the beginning of the file, allowing data to be read once more from the beginning.
The rewind() function is a standard inbuilt function of the C Programming Language. Its purpose is to set the file pointer at the starting of the stream so that the stream can be used as many times as a programmer wants. This function also terminates all the errors present in the file and specifies all the insignificant functions at the end of the file pointed by indicators present in the stream.
Recommended Topics, Sum of Digits in C
Syntax of the Function
Syntax of Rewind() function is:
void rewind(FILE*stream);
Syntax of the rewind() function is the procedure through which we pass parameters to the function. Parameters of the rewind() function are described below:
- File: It represents the file that is being pointed by the indicator.
- Stream: A stream is a file pointer that indicates the file from the beginning or from the end by removing all the insignificant functions or data.
Rewind() function is of void data type and does not return any value. Its only purpose is to set file position.
Working of Rewind() Function in C
The rewind() function is also an inbuilt standard function that consists of two elements: file functions and stream. Both of these functions are entirely interdependent, meaning both functions will collectively perform the task. The rewind () function facilitates the programmers to work with internal pointers to indicate the data stream and the file. Given below are some easily explained points which describe how the rewind() function works:
- File and file objects are the two parameters on which the rewind() function operates where objects point to the stream.
- Rewind() function provides the potential to parameters that will always place the file in the starting position and towards which stream will indicate.
- Suppose the file contains any errors or irrelevant information or data unrelated to the topic, then it will not work in the same way as it should because it has the special ability to terminate the errors of irrelevant data from the file. This unique feature helps programmers to work efficiently.
- The primary function of the stream pointer is to put and fix the file at starting position.
- The data type of the rewind() function is void, which means it does not return any type of data.
- Different libraries store different functions in the C programming language, also known as headers. To use those functions, we first need to put the library/header file related to that function at the starting of the program so that the compiler can understand the meaning of that function. Rewind() function is the function of a library/header file named as <stdio.h>.
- The main functionalities of rewind() functions work only with some particular versions like ANSI/ISO 9899-1990.
- Some other functions which act similarly like the rewind() function are: fseek() function and fsetpos() function. They have minimal differences in their functionalities.
- The time complexity of the rewind() function is 0, which means this function does not have any time complexity, and it is also not a very frequently used function.
Must Read Decision Making in C