C examples for File:Text File
Write to a Text File Character by Character using the function fputc()
#include <stdio.h> int main(){/*from www .j a va 2 s . co m*/ int k = 0, n = 0; FILE *fptr; fptr = fopen("C:\\Code\\jaipur.txt", "w"); if (fptr != NULL) { puts("File is opened successfully."); puts("Enter * to terminate the text-entry-session."); n = getchar(); while(n != '*'){ fputc(n, fptr); n = getchar(); } k = fclose(fptr); if(k == -1) puts("File-closing failed"); if(k == 0) puts("File is closed successfully."); } else puts("File-opening failed"); return(0); }