Home » C programs » stdio.h header file functions

fgetc() function in C language with Example

Here, we are going to learn about the fgetc() function of library header stdio.h in C language with its syntax, example.
Submitted by Souvik Saha, on January 06, 2019

fgetc() function in C


    int fgetc(FILE *filename);


    FILE *filename

Return type: int

Use of function:

In the file handling, through the fgetc() function we take the next character from the input stream and increments the file pointer by one. The prototype of the function fgetc() is: int fgetc(FILE* filename);

It returns an integer value which is conversion of an unsigned char. It also returns EOF which also in turns an integer value.

fgetc() example in C

#include <stdio.h>
#include <stdlib.h>

int main()
	//Initialize the file pointer
	FILE *f;								
	char ch;
	//Create the file for write operation
	printf("Enter five character\n");
	for(int i=0;i<5;i++){
		//take the characters from the users
		//write back to the file
		//clear the stdin stream buffer
	//close the file after write operation is over
	//open a file
	printf("File content is--\n");
	printf("\n...............print the strings..............\n\n");
		//takes the characters in the character array 
		//and print the characters


	return 0;


fgetc example in c

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.