hey, how do i check the directory that the program is being run from? i need to do this so that i can create a file in that directory so that LATER when i check for the file, it won't always NOT exist. lol thanks
hey, how do i check the directory that the program is being run from? i need to do this so that i can create a file in that directory so that LATER when i check for the file, it won't always NOT exist. lol thanks
Registered Linux User #380033. Be counted: http://counter.li.org
> how do i check the directory that the program is being run from?
1. this depends on your OS and Compiler.
2. If the user types in a relative path, which answer do you mean?
Eg. prog and data are two sub directories
cd data
../prog/myprog.exe
Now do you want 'data' - which you can get with getcwd()
Or do you want 'prog', the actual directory where the program executable is found?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
OS: Windows XP
Compiler: Dev-C++ 4.9.9.2 IDE
Well what i want to do is let the user enter a "main password" for some added security. a user of the program i wrote may encrypt / decrypt a file, but theres nothing stopping someone else using the same program from decrypting the file. this program will not be widely distributed and is mainly for me & one of my friends personal purposes. but you can set a main password which creates a password file, and if this file exists - the program will not decrypt a file until the master password has been entered (it prompts for the master pw). but i would like to store the password file in the same directory as the executable, not in the current working directory the user has chosen. also, when checking for the file - it checks in the current working directory the user has chosen. so i need to be able to store the file in the directory of the executable, and then check for the file in the directory of the executable.
thanks
Registered Linux User #380033. Be counted: http://counter.li.org
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
getcwd() would also work if you're using Dev-C++.
Better - no need to strip the name of the exe (or dll).Originally Posted by Ken Fitlike
http://msdn.microsoft.com/library/de...tdirectory.asp
As detailed by Salem, GetCurrentDirectory or getcwd return, suprisingly enough, the current directory, which is often not the same as the executable directory. In fact, if you launch a windows executable by dragging a file on to it, GetCurrentDirectory seems to return a random directory. Strip the file name from the result of GetModuleFileName.
Storing things in the same directory as the executable seems crude to me.
It's also a bit obvious having myprog.exe and password.txt in the same place IMO.
In most cases, you should really be looking at say
- the user's home directory (or somewhere beneath it)
- in the case of windows, somewhere in the user's area of the registry.
I hope you're storing the hash of the password rather than the password itself.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
__FILE__ would work if you don't rename the file after it was compiled, but you guys are right, GetModuleFileName would be better.
lol dont worry salem, the password does get encrypted before storage and its encrypted with a different algorithm than the one used to encrypt regular text input in the program so someone can't choose the "decrypt" function and view the password i've thought of this.
but the registry would be a good idea for windows..i agree about that. then i dont have to care about what the working directory is..but how do i check if the reg key exists or not?
thanks guys.
Registered Linux User #380033. Be counted: http://counter.li.org
tryOriginally Posted by willc0de4food
http://msdn.microsoft.com/library/de...reatekeyex.asp
or
http://msdn.microsoft.com/library/de...gopenkeyex.asp
see also the alphabetical listing of functions in the API:
http://msdn.microsoft.com/library/de...ical_order.asp
It's been awhile since I touched API programming, so I don't remember for sure how to use them, but hopefully you can find the information somewhere there in the maze that is the MSDN reference section :-)
James G. Flewelling
Rgistered Linux User #327359
Athabasca University Student (BSc. CIS)
http://catb.org/~esr/faqs/smart-questions.html
http://catb.org/jargon/
http://www.ebb.org/ungeek
---GEEK CODE---
Version: 3.12
GCS/IT/M d- s+:++ a-->->>+>++>+++>? C++++>$ UL++>++++$ P++>++++ L++>++++$
E W++ N o? K? w++(--)>--- O? M? V? PS--(---) PE Y+ PGP? t 5? !X R(*)>++
tv-->! b++(+++)>++++ DI? D+++(---)>++++$ G e*>++$ h++>*$ r!>+++ y?
----/GEEK CODE----
upd: 2005-02-11