user-0 提问: fopen函数创建文件失败

回复:
user: user-0
content: 感谢楼上各位的回复，受教了

user: user-1
content: 引用 5 楼 zhao4zhong1 的回复:_setmaxstdio Sets a maximum for the number of simultaneously open files at the stdio level.   int _setmaxstdio( int newmax );  Routine Required Header Compatibility  _setmaxstdio <stdio.h> Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  Returns newmax if successful; –1 otherwise.   Parameter  newmax  New maximum for number of simultaneously open files at the stdio level  Remarks  The _setmaxstdio function changes the maximum value for the number of files which may be simultaneously open at the stdio level.   C run-time I/O now supports many more open files on Win32 platforms than in previous versions. Up to 2,048 files may be open simultaneously at the lowio level (that is, opened and accessed by means of the _open, _read, _write, and so forth family of I/O functions). Up to 512 files may be open simultaneously at the stdio level (that is, opened and accessed by means of the fopen, fgetc, fputc, and so forth family of functions). The limit of 512 open files at the stdio level may be increased to a maximum of 2,048 by means of the _setmaxstdio function.  Since stdio level functions, such as fopen, are built on top of the lowio functions, the maximum of 2,048 is a hard upper limit for the number of simultaneously open files accessed through the C run-time library.  Note   This upper limit may be beyond what is supported by a particular Win32 platform and configuration.     Stream I/O Routines 赵老师果然强大

user: user-2
content: 楼主，我建议你用CreateFile函数，WriteFile函数和CloseHandle函数来完成操作。 因为这些是正规的API函数。

user: user-3
content: _setmaxstdio Sets a maximum for the number of simultaneously open files at the stdio level.   int _setmaxstdio( int newmax );  Routine Required Header Compatibility  _setmaxstdio <stdio.h> Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  Returns newmax if successful; –1 otherwise.   Parameter  newmax  New maximum for number of simultaneously open files at the stdio level  Remarks  The _setmaxstdio function changes the maximum value for the number of files which may be simultaneously open at the stdio level.   C run-time I/O now supports many more open files on Win32 platforms than in previous versions. Up to 2,048 files may be open simultaneously at the lowio level (that is, opened and accessed by means of the _open, _read, _write, and so forth family of I/O functions). Up to 512 files may be open simultaneously at the stdio level (that is, opened and accessed by means of the fopen, fgetc, fputc, and so forth family of functions). The limit of 512 open files at the stdio level may be increased to a maximum of 2,048 by means of the _setmaxstdio function.  Since stdio level functions, such as fopen, are built on top of the lowio functions, the maximum of 2,048 is a hard upper limit for the number of simultaneously open files accessed through the C run-time library.  Note   This upper limit may be beyond what is supported by a particular Win32 platform and configuration.     Stream I/O Routines

user: user-0
content: 引用 2 楼 zjq9931 的回复:因为你创建打开后不关闭，句柄资源被用完后就出错了。  新手还不知道句柄，刚才查了  谢谢~

user: user-0
content: 引用 1 楼 user-4 的回复:检查返回值 及 errno  判断 失败原因  具体看：http://en.cppreference.com/w/c/io/fopen  多谢！

user: user-1
content: 因为你创建打开后不关闭，句柄资源被用完后就出错了。

user: user-4
content: 检查返回值 及 errno  判断 失败原因  具体看：http://en.cppreference.com/w/c/io/fopen