80489874 on the same csdn
C Language Get executable file (XXX.exe) filename and directory path
Vc2010 compiled by
1#include <stdio.h>2#include <string.h>3#include <windows.h>4#include <stdlib.h>5 6 intMainintargcChar*argv[]) {7 8printf"%s\n", argv[0]);//argv[0] Output path with the main function parameter9 Ten Charpath[ -]; OneGetModuleFileName (NULL, Path, -);//Call the win API to get the path Aprintf"%s\n", path); - - Char*p = STRRCHR (Path,'\\');//Intercept to the last "\", followed by the XXX.exe file name theprintf"%s\n", p); - - Char*name = p +1;//truncate "\", leaving only the file name -printf"%s\n", name);//Output File name + - Charpath2[ -]; +GetCurrentDirectory ( -, path2);//get the current process directory path, different from the above, you can try it yourself Aprintf"%s\n", path2); at -System"Pause"); - return 0; -}
C Language Get executable file (XXX.exe) filename and directory path