C Fputc And Fgetc

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: