I'm running this on Lubuntu in a virtual machine using Oracle's VirtualBox. I don't think that would affect anything, but I just thought it was worth mentioning.
It appears the error is appearing from a strange symbol appended to the end of the string returned by the following function:
inline std::string f_settings_get(std::string val){
int index=0;
while(strcmp(val.c_str(),f_settings[0][index].c_str())!=0){
index++;
};
// For debugging purposes - printf("\n%s\t%s",f_settings[0][index].c_str(),f_settings[1][index].c_str());
return f_settings[1][index];
}
I can't see an issue with this function and thus believe it might be caused by the data stored in the variable.
I have been trying to open a file in my program using fopen
and have come across the error stated in the title. The code works perfectly in Windows (and I have accounted for the /
and \
for each operating system); however, when running on Linux, although it compiles perfectly, I get the error that the file does not exist. I checked online and found several issues others have had such as:
I checked the first out by using the Python script supplied, and recreating the file with a new name. That didn't work (and the Python script showed that the filename was good).
I set all permissions to being 777 using chmod -R 777 clesis
and that did not work (though I didn't expect it to be a permissions issue as it said the file did not exist).
I have the full path already called and double checked the path. It is correct.
Finally, I ran the following in the code to double check that: (a) The file existed and (b) I was trying to open the correct file.
tmp_s="";
tmp_s = homeDir+binP+f_settings_get("xxxxx"); // Note, you can easily get whatever variable you want using either f_settings_get or num_settings_get
tmp_file = fopen(tmp_s.c_str(), "r+");
printf("\n Running the following command: /home/xxxxx/programming/xxxxx/bin\n");
std::system("ls -l /home/xxxxx/programming/xxxxx/bin");
getWait();
printf("\n Tried to open: %s", tmp_s.c_str());
if (tmp_file == NULL){
printf("\n");
perror("Error loading dimensions.sim");
printf("Press enter to exit...");
getWait();
exit(1);
}
And here's how the output looks (sorry for censoring things. I assure you the user name and folder are spelled the same):
The output shows the following:
Filenames Loaded...
Loading Settings from sim file...
++++++++++++++++++++++++++++++++++++++++++++++++++ Settings Loaded...
Loading System Dimensions from sys file...
--------------------------------------------------
Running the following command: /home/xxxxx/programming/xxxxx/bin
total 636
-rwxrwxrwx 1 xxxxx xxxxx 958 Jul 25 20:59 dimensions.sim
Tried to open: /home/xxxxx/programming/xxxxx/bin/dimensions.sim
Error loading dimensions.sim: No such file or directory
Press enter to exit...
If the file path is specified directly as "bin/dimensions.sim" or "/home/xxxxx/programming/xxxxx/bin/dimensions.sim" then it works properly. This leads me to a confused conclusion. That somewhere in the conversion of tmp_s
from a std::string
to a c_str
there is an issue that is leading to a wrong directory path. However, this doesn't occur with any of the other files I'm using, and I have never had this issue on a Windows machine. Thus I am confused as to what may be causing it.
One last observation - the conversion was printed out anyway using the printf("tmps = %s",tmp_s.c_str());
. And that can be clearly seen to not be 'weird'.