C examples for File:Text File
Fputs() reads strings from the keyboard and writes them to the file.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char str[80];/*from ww w . java2s .c o m*/ FILE *fp; if ((fp = fopen("TEST", "w")) == NULL) { printf("Cannot open file.\n"); exit(1); } do { printf("Enter a string (CR to quit):\n"); gets_s(str); strcat(str, "\n"); /* add a newline */ fputs(str, fp); } while (*str != '\n'); return 0; }