2002-05-28 21:13:45 +08:00
|
|
|
/*
|
|
|
|
* A sample program demonstrating how to use fmode to change the default
|
|
|
|
* file opening mode to binary. NOTE: Does not change stdin, stdout or
|
|
|
|
* stderr.
|
|
|
|
*
|
|
|
|
* THIS CODE IS IN THE PUBLIC DOMAIN.
|
|
|
|
*
|
|
|
|
* Colin Peters <colin@fu.is.saga-u.ac.jp>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2002-10-03 08:49:21 +08:00
|
|
|
#include <stdlib.h> /* _fmode */
|
|
|
|
#include <fcntl.h> /* _O_BINARY */
|
2002-05-28 21:13:45 +08:00
|
|
|
|
|
|
|
main ()
|
|
|
|
{
|
|
|
|
char* sz = "This is line one.\nThis is line two.\n";
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
_fmode = _O_BINARY;
|
|
|
|
|
|
|
|
printf (sz);
|
|
|
|
|
|
|
|
/* Note how this fopen does NOT indicate "wb" to open the file in
|
|
|
|
* binary mode. */
|
|
|
|
fp = fopen ("test.out", "w");
|
|
|
|
|
|
|
|
fprintf (fp, sz);
|
|
|
|
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
|