Posts

C Program to open and write to a text file using fprintf.

  C Program to  open and write to a text file using fprintf. # include <stdio.h> #include <conio.h>  # include <string.h>   void  main( ) {    FILE *fptr ;   char data[100] = “Welcome to Code Hub-A Computer Science Portal for Engineering UG and PG students";  fptr = fopen("program.c", "w") ;  if(fptr == NULL )     { printf( "program.c file failed to open." ) ;     }     else     {  printf("The file is now opened\n") ;   i f (strlen(data) > 0 )         {  fputs(data,  fptr ) ;      fputs("\n",  fptr ) ;         }     fclose( fptr ) ; printf("Data successfully written in file \n"); printf("The file is closed.") ;     }      getch();   }

C Program to open and write to a text file using fprintf.

  C Program to  open and write to a text file using fprintf. #include <stdio.h> #include <conio.h>  #include <stdlib.h>   void   main() {    int number;    FILE *fileptr; fileptr = fopen("D:\\program.txt","w");    if( fileptr == NULL)    {       printf("Error in file !");         exit(1);                } printf("Enter number: "); scanf("%d",&number); fprintf( "fileptr %d",number);    fclose( fileptr );      getch();    }