Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

The fgetc() function

The function fgetc() is used to read a single character at a time from the file. At the end of a file, it returns EOF.

Syntax

int fgetc(FILE *fp)

Example

Inside file2.txt

C Programming Language fgetc Function in File Handling Example

#include<stdio.h>

int main()
{
    FILE *fp;
    char ch;
    fp=fopen("D:\\C Programming\\file2.txt","r");
    if(fp==NULL)
    {
        printf("\n Unable to open the FILE");
        return 1;   
    }
     
    ch=fgetc(fp);
    while(ch!=EOF)
    {
        printf("%c",ch);
        ch=fgetc(fp);
    }
    fclose(fp);
    return 0;
}

Output

C Programming Language fgetc Function in File Handling Example Output
 

Leave a reply