fopen("abc.txt", "w"); 文件建在哪儿的问题
FILE* logfile = fopen("abc.txt", "w");
fclose(logfile);
The _getcwd function gets the full path of the current working directory for the default drive and stores it at buffer. The integer argument maxlen specifies the maximum length for the path. An error occurs if the length of the path (including the terminating null character) exceeds maxlen. The buffer argument can be NULL; a buffer of at least size maxlen (more only if necessary) will automatically be allocated, using malloc, to store the path. This buffer can later be freed by calling free and passing it the _getcwd return value (a pointer to the allocated buffer).
_getcwd returns a string that represents the path of the current working directory. If the current working directory is the root, the string ends with a backslash ( \ ). If the current working directory is a directory other than the root, the string ends with the directory name and not with a backslash.
_wgetcwd is a wide-character version of _getcwd; the buffer argument and return value of _wgetcwd are wide-character strings. _wgetcwd and _getcwd behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tgetcwd _getcwd _getcwd _wgetcwd
Example
// GETCWD.C
/* This program places the name of the current directory in the
* buffer array, then displays the name of the current directory
* on the screen. Specifying a length of _MAX_PATH leaves room
* for the longest legal path name.
*/
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char buffer[_MAX_PATH];
/* Get the current working directory: */
if( _getcwd( buffer, _MAX_PATH ) == NULL )
perror( "_getcwd error" );
else
printf( "%s\n", buffer );
}
Output
C:\code
Directory Control Routines
See Also _chdir, _mkdir, _rmdir
GetCurrentDirectory
The GetCurrentDirectory function retrieves the current directory for the current process.
DWORD GetCurrentDirectory(
DWORD nBufferLength, // size, in characters, of directory buffer
LPTSTR lpBuffer // pointer to buffer for current directory
);
Parameters
nBufferLength
Specifies the length, in characters, of the buffer for the current directory string. The buffer length must include room for a terminating null character.
lpBuffer
Pointer to the buffer for the current directory string. This null-terminated string specifies the absolute path to the current directory.
Return Values
If the function succeeds, the return value specifies the number of characters written to the buffer, not including the terminating null character.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the buffer pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, including the number of bytes necessary for a terminating null character.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
See Also
File I/O Overview, File Functions, CreateDirectory,GetSystemDirectory,GetWindowsDirectory, RemoveDirectory, SetCurrentDirectory