fclose() Function in C Last Updated : 07 Aug, 2024 Comments Improve Suggest changes Like Article Like Report In C language, fclose() is a standard library function used to close a file that was previously opened using fopen(). This function is the itegral part of the file handling in C which allows the users to free the memory occupied by the file once all the operations are done on it.In this article, we will learn about the fclose() function, its syntax and how it behaves in different scenarios.Syntax of fclose()The syntax of fclose is straigforward:fclose(file_pointer);Parametersfile_pointer: A pointer to a FILE object that identifies the stream to be closed.Return ValueThis function only returns two values:0: When the file is successfully closed.EOF: When an error occurred while closing the file.Example of fclose() in C C // C program to demonstrate the use of fclose() #include <stdio.h> int main() { // Open the file for writing FILE *file_ptr = fopen("example.txt", "w"); if (file_ptr == NULL) { perror("Error opening file"); return 1; } // Write some data to the file fprintf(file_ptr, "Hello, World!\n"); // Close the file and check for errors if (fclose(file_ptr) != 0) { perror("Error closing file"); return 1; } printf("File operations completed successfully.\n"); return 0; } OutputFile operations completed successfully. Note: Using the file stream after it has been closed with fclose() results in undefined behavior. This means that any operations on the closed file stream can lead to unpredictable results, including crashes or data corruption.Related Articles:Basics of File Handling in CC fopen() Function in C Comment More infoAdvertise with us Next Article fclose() Function in C A abhishekcpp Follow Improve Article Tags : C Language C-Functions C-File Handling Similar Reads clock() function in C The clock() function in C returns the approximate processor time that is consumed by the program which is the number of clock ticks used by the program since the program started. The clock() time depends upon how the operating system allocates resources to the process that's why clock() time may be 2 min read fabs() Function in C fabs() function of math.h header file in C programming is used to get the absolute value of a floating point number. This function returns the absolute value in double. Syntax: double fabs (double a); Parameter: It will take a single parameter which is to be converted to an absolute value. Return Va 2 min read fmod() Function in C The fmod() function in C computes the floating-point remainder of the division of two numbers. It is part of the math library <math.h> in C and <cmath> in C++.fmod() in CThe fmod() function returns the remainder of the division of two floating-point numbers. It is particularly useful whe 3 min read C fopen() Function In C, the fopen() function is used to open a file in the specified mode. The function returns a file pointer (FILE *) which is used to perform further operations on the file, such as reading from or writing to it. If the file exists then the fopen() function opens the particular file else a new file 5 min read C floor() Function The floor(x) function in C is used to compute the largest integer value less than or equal to a given number. This function is particularly useful in mathematical computations where rounding down to the nearest integer is required.Header Files UsedTo use the floor(x) function, you need to include th 3 min read Like