| demosthenes2k8 (174) | |||
|
This is a small sample of code that I've been having trouble with. For some reason, even though config_filename stores (and outputs) the correct file location, it still displays the error. It compiles fine, but I get the message "The settings file is missing, please create the config.orc file" when I run it, along with the path of a file that I KNOW is there. Is there anything obviously wrong with this code?
| |||
|
Last edited on
|
|||
| Bazzy (6275) | |
| Be sure that the working directory of your program is correct | |
|
|
|
| chrisname (5253) | |
|
Are you sure you have permission to read the file? You could use stat() to check. Or you could look at errno. | |
|
|
|
| demosthenes2k8 (174) | |
|
What would cause a working directory to be incorrect? The reason why this is troublesome is that eventually the goal is to be able to run the program from anywhere thanks to PATH. Therefore, the working directory might be anywhere. Errno is 0 after the call (I output it after the cout << config_filename;) and I even tried chmod 7777 config.orc, and sudo su. The program still can't read the file. | |
|
|
|
| chrisname (5253) | |||
What's this for:(void)argv,(void)argc;To avoid gcc complaining about you not using them? I usually just do this:
Compiler probably gets rid of it but it avoids the error checking until I actually want to use them. | |||
|
Last edited on
|
|||
| moorecm (1732) | |
| Are you trying to open an fstream in the virtual filesystem /proc? I've never tried that... | |
|
|
|
| demosthenes2k8 (174) | |
|
No, I use /proc with the pid to get the location of the executable. It outputs that correctly, though. Yeah, I'm more used to casting them as (void) instead of doing that, chrisname. Reason being I can simple #define UNUSED (void) and the UNUSED argc;
| |
|
|
|
| chrisname (5253) | ||
|
It should work: http://i32.tinypic.com/1qphly.jpg Edit: @demosthenes2k8 Good idea.
Can't you just get that from argv[0] and getcwd()? | ||
|
Last edited on
|
||
| demosthenes2k8 (174) | |
|
Nope. The reason being the above: if the path to the executable's stored in PATH, then argv[0] will just be "Oratr", not the actual path. And for the same reason, getcwd will return a bad value, because it's not being called from the directory that it's located in. The fact that it's an absolute path wouldn't have anything to do with it, right? | |
|
|
|
| moorecm (1732) | |
| What's wrong with a relative path?! This whole thing seems silly to me. | |
|
|
|
| chrisname (5253) | ||||
This works:
| ||||
|
|
||||
| demosthenes2k8 (174) | |
| Yeah, that should work, but that's not the problem. The problem is that the fstream doesn't open the file that is at that location. | |
|
|
|
| chrisname (5253) | |
| Yes, but it fixes the issue of having to go through /proc just to find your executable file. | |
|
|
|
| demosthenes2k8 (174) | |
|
That code still fails when the program's folder is in the PATH, though. http://dl.dropbox.com/u/285110/PATH.png | |
|
|
|
| chrisname (5253) | |
|
Does stat() tell you the file exists? Also, nice bash prompt. What character is joining the brackets on the far left? And how do you get the time to update between prompts? | |
|
|
|
| demosthenes2k8 (174) | |
|
Yeah, that helped me fix it. Apparently it was appending the name of the file onto the string, which caused it to error. Thanks, I honestly just hacked it together from two other prompts that I liked. I don't know how to make a prompt, but I can definitely edit one! PS1="\[\033[0;36m\]\033(0l\033(B\[\033[0m\][\[\033[1;31m\]\u\[\033[0m\]]\[\033[0;36m\]\033(0q\033(B\[\033[0m\][\[\033[1;33m\]@\h\[\033[0m\]]\[\033[0;36m\]\033(0q\033(B\[\033[0m\][\[\033[0;37m\]\T\[\033[0m\]]\[\033[0;36m\]\033(0q\033(B\033(0q\033(B\033(0q\033(B\033(0q\033(B\033(0q\033(B\033(0q\033(B\033(0q\033(B\033(0q\033(B\[\033[0m\][\[\033[1;33m\]\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; fi\`\[\033[0m\]]\n\[\033[0;36m\]├\[\033[0m\][\[\033[1;33m\]\w\[\033[0m\]]\n\[\033[0;36m\]\033(0m\033(B\[\033[0m\]>"Both of the two that I used to make this were at http://maketecheasier.com/8-useful-and-interesting-bash-prompts/2009/09/04 | |
|
|
|