#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>
char* get_file_path(char* dir, char* fname)
{
dir = _getcwd(dir, MAX_PATH);
strcpy(&dir[strlen(dir)], "\\");
strcpy(&dir[strlen(dir)], fname);
return dir;
}
int main(int argc, char* argv[])
{
/* uncomment
if(argc != 1)
{
printf("error: usage myapp.exe file.txt\n");
return -1;
}
uncomment */
char dir[MAX_PATH];
char* file = "file.txt";//test
char* full_file_name = get_file_path(dir, file);// get_file_path(dir, argv[0])
FILE* fp = fopen(full_file_name, "r");
if(fp)
{
printf("Open\n");
fclose(fp);
}
printf("%s", full_file_name);
free(full_file_name);
return 0;
}
gcc -static