Discuss Path to program's directory in the C Programming forum on Dev Shed. Path to program's directory C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 186
Time spent in forums: 3 Days 15 h 8 m 51 sec
Reputation Power: 9
Quote:
Originally Posted by JSClark
Is this for any Visual C / C++ Applications by any odd chance?
I do not have much experience with MSVS, but I think, my DOS/Windows example should work. You can find some information in MSDN. (Plz let me know, if it works...)
Posts: 2,768
Time spent in forums: 1 Month 4 Weeks 18 h 20 m 6 sec
Reputation Power: 1237
Mareq, your answer only tells the current directory, not where the program is found. Most programs are found in one of the directories listed in the PATH variable.
Even then, you can add extra complexity to the problem by specifying a relative path to a program which isn't on the PATH, eg
..\foo\bar\prog.exe
Posts: 186
Time spent in forums: 3 Days 15 h 8 m 51 sec
Reputation Power: 9
Quote:
Originally Posted by salem
Mareq, your answer only tells the current directory, not where the program is found. Most programs are found in one of the directories listed in the PATH variable.
Even then, you can add extra complexity to the problem by specifying a relative path to a program which isn't on the PATH, eg
..\foo\bar\prog.exe
Current path is at start the path of progam, but yes, you're right, if you explicitly change current directory... (Is this true? I'm not sure.)
Posts: 5,550
Time spent in forums: 2 Months 2 Weeks 14 h 30 m 52 sec
Reputation Power: 3285
Quote:
Originally Posted by Mareq
Current path is at start the path of progam
That's not true. The current path at the start of execution is whatever path you were in. For instance say you open up a command prompt in XP and go to some directory (say your home dir, c:\documents and settings\yourname) to do something, then you execute notepad. notepad.exe is in C:\Windows, but the current path as returned by getcwd in notepad would be c:\documents and settings\yourname.
Posts: 8
Time spent in forums: 1 h 43 m 27 sec
Reputation Power: 0
I found the way how to get the path on Linux - it's in /proc/self/maps. So i wrote this function, which gets the path from this file:
Code:
char *wd;
wd=new char[100]; //alocate the memory
FILE *f;
char tmp[200];
char *tmp2,*tmp3;
f=fopen("/proc/self/maps","r"); //that file contains path to my aplication
fgets(tmp,200,f); //read the first line
fclose (f);
tmp[strlen(tmp)-1]='\0'; //remove newline character
tmp2=strchr(tmp,'/'); //find first slash
tmp3=strrchr(tmp,'/'); //find the last slash
*tmp3='\0'; //tarminating character replaces last slash of path
sprintf(wd,"%s",tmp2); //copy path on the other place in memory
return (wd);