My Subject Blog

C Program for Basic File Operation

/*
Write a program to create a file and perform basic I/O operations on the same. 
*/


#include<stdio.h>

int main() 
{
   
FILE *fp;
   
int ch;
   
fp=fopen("Test.txt","w");
   
if(fp == NULL) 
{
perror("Error opening file");
return(-1);
}
putc('A',fp);
   
fclose(fp);

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

if(fp == NULL) 
{
perror("Error opening file");
return(-1);

ch=getc(fp);
   
printf("CHAR = %c",ch);
   
fclose(fp);
   
return 0;

Comments

Most Visited Post

C Program to Find Largest Odd Number from Array

Followers