windows下c语言获取程序当前的执行目录,读文件的代码片

时间:2023-03-08 15:53:05

代码如下:

#include "stdafx.h"
#include "stdlib.h"
#include <direct.h>
#include <string.h> int _tmain(int argc, char* argv[])
{
char* buffer; // Get the current working directory:
if( (buffer = _getcwd( NULL, 0 )) == NULL )
perror( "_getcwd error" );
else
{
printf( "%s \nLength: %d\n", buffer, strnlen(buffer,1024) );
free(buffer);
} FILE *fp = fopen("input_left.ppm", "rb");
if (!fp)
{
printf("exit");
return NULL;
}
else
{
printf("get");
} getchar(); return 0;
}