How to get the path of current working directory

Started by
4 comments, last by j_smith4 16 years, 3 months ago
Hi What is require is to get the path of current working directory.I m working on windows-XP. Is any function avaliable in c/c++ i could find on net #include <unistd.h> char *getcwd(char *buf, size_t size); But not working i don't know why. Can u provide small code of how to use this function or any other function which can do the above task in a better way.
Advertisement
Fairly sure that header is only good in Linux. In Windows GetCurrentDirectory() will do what you need. A little Googling says that function is in direct.h, which works in VS6.
--------Ratings - Serious internet buisness
Quote:Original post by j_smith4
Fairly sure that header is only good in Linux. In Windows GetCurrentDirectory() will do what you need. A little Googling says that function is in direct.h, which works in VS6.
At the bottom of the page you linked it says:
Quote:Header Declared in WinBase.h; include Windows.h.

I have used GetCurrentDirectory() like

string Path_value= GetCurrentDirectory();

But it is giving me compilation errors.
1345 C:\Dev-Cpp\include\winbase.h too few arguments to function `DWORD GetCurrentDirectoryA(DWORD, CHAR*)'
What kind of argument it is expecting.

Also i m using Dev-CPP4.9.9.2


If you read the article at the link j_smith4 provided, it says that you need to supply two arguments. The first one is the length of the buffer for the current directory string, and the second one is what receives the actual directory string.

Perhaps it'll help if you take a look at this example.
Jack
Quote:Original post by mutex
At the bottom of the page you linked it says:
Quote:Header Declared in WinBase.h; include Windows.h.


It was late and reading it again I didn't word it well. GetCurrentDirectory works fine if you want to use the Windows API, but after I posted I thought maybe he was looking for something thats part of the C libraries instead. And on non Linux getcwd() was moved to direct.h, why they couldn't have just kept unistd.h I don't know.

TCHAR path_value[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path_value);

MAX_PATH is defined in the windows headers as the max length of a valid file name in Windows.
--------Ratings - Serious internet buisness

This topic is closed to new replies.

Advertisement