File Operations in Tamil


 c-fgetc

Learn C - C tutorial - C fgetc - C examples - C programs

C - fgetc() - Definition and Usage

  • In C - Programming, the getc function is used to read the character from the file.
C fgetc

C Syntax

 int getc( FILE * stream ); 

Sample - C Code

#include <stdio.h>
#include <conio.h>
void main()
{
    FILE *fp = fopen("sample.txt", "r");
    int ch = getc(fp);
    while (ch != EOF)
    {
        /* To display the contents of the file on the screen */
        putchar(ch);
        ch = getc(fp);
    }
    fclose(fp);
    getch();
}

C Code - Explanation

code-explanation-fgetc
  1. Here in this statement we create a file pointer “fp”.
  2. Here in this statement we get the character value for the text file using “getc” function where its values are assigned to the variable “ch”.
  3. In this while loop statement we check whether the document contains any text or not.
  4. In this statement we write the character in the display window.
  5. In this we assign the file pointer to the variable “ch”.
  6. After the completion of file manipulation, the file will be closed using fclose function.

Sample Output - Programming Examples

code-explanation-fgetc-output
  1. Here in this output the statement “WelcomeToWikitechy” in the notepad file (sample.txt) has been shown which is located in the BIN folder of C.
code-explanation-fgetc-output1
  1. Here the text content (“WelcomeToWikitechy”) from notepad file (sample.txt) has been shown in the console window.

View More Quick Examples


Related Searches to c fgetc