/* Test program file2 This example demonstrates how to create a simple text file and to write text to it. The file can be tested with any text editor or with test program file1. Author: PS-Trainer 2001.12.01 */ // fopen( outfile, "wt" ) // write new (delete old), text // fopen( outfile, "at" ) // append (must exist), text // fputs( string, stream ) // write string to stream // test = putc( ch, stream ) // write char to stream // fclose( stream ) // close #include #include #include void main( void ) { FILE *stream; int iok, zeile; char line[100]; char outfile[]="dataout.txt"; zeile=0; if( (stream = fopen( outfile, "wt" )) != NULL ) { printf("> File %s opened for output\n",outfile); iok++; line[0]='$'; line[1]='\0'; while ( strlen(line)>0) { printf( ">Write line %3d: ",zeile++); gets(line); fputs(line,stream); fputs("\n",stream); } fclose( stream ); printf("\n> File %s was closed\n",outfile); } else printf("> Error: File %s could not open\n",outfile); // show console window until key pressed printf("\nType any key to exit this program.\n"); _getch(); }