fgetc() is used to obtain input from a file single character at a time. This function returns the number of characters read by the function. It returns the character present at position indicated by file pointer. After reading the character, the file pointer is advanced to next character. If pointer is at end of file or if an error occurs EOF file is returned by this function.
int fgetc(FILE *pointer) pointer: pointer to a FILE object that identifies the stream on which the operation is to be performed.
The entire content of file is printed character by character till end of file. It reads newline character as well.
fputc() is used to write a single character at a time to a given file. It writes the given character at the position denoted by the file pointer and then advances the file pointer.
This function returns the character that is written in case of successful write operation else in case of error EOF is returned.
int fputc(int char, FILE *pointer) char: character to be written. This is passed as its int promotion. pointer: pointer to a FILE object that identifies the stream where the character is to be written.
When fputc() is executed characters of string variable are written into the file one by one. When we read the line from the file we get the same string that we entered.
This article is contributed by Hardik Gaur. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- What is return type of getchar(), fgetc() and getc() ?
- How does Volatile qualifier of C works in Computing System
- Header files in C/C++ with Examples
- C Programming For Beginners - A 20 Day Curriculum!
- Tr0ll 3 Walkthrough of Check the Flag or CTF Problem
- What are the C programming concepts used as Data Structures
- Array of Structures vs. Array within a Structure in C/C++
- Difference between Identifiers and Variables in C
- Difference between C and Objective C
- Strict Aliasing Rule in C with Examples
- Difference between C and Dart
- Difference between Sentinel and Counter Controlled Loop in C
- Why do we need reference variables if we have pointers
- What are the differences between C and Embedded C?