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(); }