#include #include #define MAXCHAR 100 // examples of using fgets() and fputs(). // Enter text at the terminal until (control d) ^d. The text will be // written to a file. int main (void) { char str[MAXCHAR]; FILE *file; if (!(file = fopen ("myfile.txt", "w"))) { printf("Can't open file\n"); exit (1); } // read in a characters from the keyboard and write them to a file // then close the file. while (fgets(str, sizeof(str), stdin)) fputs(str, file); fclose (file); return EXIT_SUCCESS; }