hi guys i want to make a c program,what it has to do is to find its current pathname every time it is executed from diferent locations and then redirect the outcome in a .txt file,through cmd.I have lack of knowledge when it comes to cmd so any help?

Recommended Answers

All 7 Replies

Try the system function call...
It takes strings (your command) as arguments to it and runs that command at the console.
So for your purpose, you can try this...

system("pwd >>file.txt");

So, pwd command will get the current working directory and >> will redirect the output and append it to the text file named file.txt.
Cheers,

well about the system command..i know that this will work in unix enviroment the problem is i want to make it work in windows..

Dear libathos,
system function call is work with Windows also...so it will not be a problem.
If you are having a static string as command like "pwd" you can directly have it in system() call. If, otherwise you want to include any variable then you can use sprintf before it.
Example:

sprintf(command, "nbtstat -A %d.%d.%d.%d" ,a,b,c,d);
system(command);

Otherwise, I think it should work fine...

no you didnt understand correctly...i know how to use the system command..i dont know the equal for pwd...

it's okay guys consider it answered thx anyway

You can use "chdir" command in windows in place of "pwd".
Cheers,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.