C Programming
Computer Programming

C file handling program to create, open and close a file



Write C file handling program to create, open and close a file

\* C file handling program to create, open and close a file *\

# include < stdio.h >
# include < stdlib.h >
int   main( )
{

/* file pointer*/
FILE *fp ;
char fName[20] ;

printf("\n Enter file name to create :") ;
scanf("%s", fName ) ;

/*creating (open) a file, in "w": write mode*/
fp=fopen(fName, "w" ) ;

/*check file created or not*/
if( fp == NULL )
{
      printf(" File does not created!!!" ) ;
      exit(0) ;
}
printf(" File %s is created successfully.", fName) ;
return 0 ;

}

Output of Program :

Output of C file handling program to create, open and close a file