C Programming
Computer Programming

C file handling program to create a File and Store Information



Write C file handling program to create a File and Store Information

\* C file handling program to create a File and Store Information *\

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

FILE *fptr ;
char name[20] ;
int age ;
float salary ;

/* open for writing */
fptr = fopen("employee.txt", "w");
if ( fptr == NULL )
{
      printf("\n File does not exists !\n") ;
      return 0;
}
printf("\n Enter the name : ") ;
scanf("%s", name) ;
fprintf(fptr, " Name = %s\n", name ) ;
printf(" Enter the age : ") ;
scanf("%d", &age ) ;
fprintf(fptr, " Age = %d\n", age ) ;
printf(" Enter the salary : ") ;
scanf("%f", &salary) ;
fprintf(fptr, " Salary = %.2f\n", salary) ;
fclose(fptr) ;
return 0 ;

}

Output of Program :

Output of C file handling program to create a File and Store Information