home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / bintext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-25  |  840 b   |  35 lines

  1. /* BINTEXT.C illustrates changing between binary and text modes for
  2.  * stream I/O using function:
  3.  *      setmode
  4.  * and global variable:
  5.  *      _fmode
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <fcntl.h>
  10. #include <io.h>
  11. #include <string.h>
  12. #include <stdlib.h>         /* For _fmode and exit */
  13.  
  14. main()
  15. {
  16.     FILE *htmp;
  17.     char name[13];
  18.  
  19.     /* Set default mode to binary and open file. */
  20.     _fmode = O_BINARY;
  21.     if( (htmp = fopen( tmpnam( name ), "w+" )) == NULL )
  22.         exit( 1 );
  23.     fprintf( htmp, "\nThis\nis\nsome\nbinary\ntext.\n\n" );
  24.  
  25.     /* Flush buffer and change mode to text. */
  26.     fflush( htmp );
  27.     setmode( fileno( htmp ), O_TEXT );
  28.     fprintf( htmp, "\nThis\nis\nsome\ntext\ntext.\n\n" );
  29.     fclose( htmp );
  30.  
  31.     system( strcat( "TYPE ", name ) );
  32.     remove( name );
  33.     exit( 0 );
  34. }
  35.