C Fputc And Fgetc - C Programming Tutorial
C Course / Miscellaneous / C Fputc And Fgetc

C Fputc And Fgetc

BLUF: Understanding C Fputc And Fgetc is a foundational part of learning C programming. This tutorial explains the core principles and syntax needed to implement this concept effectively.
Core Programming Principle: C Fputc And Fgetc

C provides direct access to memory and system resources. Learn how C Fputc And Fgetc leverages this power in the lesson below.

Syntax:

Example

int fputc(int c, FILE *stream)

Example:

Example

Example

#include <stdio.h>

main(){

   FILE *fp;

   fp = fopen("file1.txt", "w");//opening file

   fputc('a',fp);//writing single character into file

   fclose(fp);//closing file

}

file1.txt

Reading File : fgetc function

The fgetc function retrieves a solitary character from the file stream, signaling the end of the file by returning EOF. This function extracts characters from the stream.

Syntax:

Example

int fgetc(FILE *stream)

Example:

Example

Example

#include<stdio.h>

#include<conio.h>

void main(){

FILE *fp;

char c;

clrscr();

fp=fopen("myfile.txt","r");



while((c=fgetc(fp))!=EOF){

printf("%c",c);

}

fclose(fp);

getch();

}

myfile.txt

Example

this is simple text message

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience