• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

C++ with Xcode (gdb?)

TheJokerV

Weaksauce
Joined
Mar 23, 2007
Messages
81
Hey guys I have a piece of code that I developed in using Visual Studio 2010 and now I need to run the code on my laptop which is a OSX machine. I know that I can't run visual studio on OSX so I'm trying to run it using XCODE. Most of the program runs fine...The only problem is when I go to output my data to a file it throws a 'EXC_BAD_ACCESS" error. I tried to create the file before hand and still has the error. The code snippet is below:

Code:
    FILE * output;
    output = fopen("results/results_12_12_1_1.txt", "w");
    if(OUTPUT_FORMAT == 1){
	    while (!outputs.empty()) {
		    outy = outputs.front();
	        fprintf(output, "%d [%d %d] [%d %d] [%d %d %d]\n", outy.transfer_id, outy.begin_loc[0], outy.begin_loc[1], outy.end_loc[0], outy.end_loc[1], outy.num_cc_bus_wait, outy.num_cc_router_int_wait, outy.num_cc_router_wait);
			outputs.pop();
		}
	}

It throws the "EXC_BAD_ACCESS" error right at the fprintf line. Does anyone know what I'm doing wrong. I'm guessing that this is just a slight difference between the windows and mac enviroment but I have no idea what that difference is.

Thanks
-Joker
 
whats in your arrays?
Break up your fprintf line and gather each data item separately and see which is causing the program to choke.
 
I don't think it has anything to do with the array/structure. For instance when I access each of the variable in the structure below:

Code:
    if(OUTPUT_FORMAT == 1){
	    while (!outputs.empty()) {
		    outy = outputs.front();
            tempy[0] = outy.transfer_id;
            tempy[1] = outy.begin_loc[0];
            tempy[2] = outy.begin_loc[1];
            tempy[3] = outy.end_loc[0];
            tempy[4] = outy.end_loc[1];
            tempy[5] = outy.num_cc_bus_wait;
            tempy[6] = outy.num_cc_router_int_wait;
            tempy[7] = outy.num_cc_router_wait;
	        fprintf(output, "%d [%d %d] [%d %d] [%d %d %d]\n", outy.transfer_id, outy.begin_loc[0], outy.begin_loc[1], outy.end_loc[0], outy.end_loc[1], outy.num_cc_bus_wait, outy.num_cc_router_int_wait, outy.num_cc_router_wait);
			outputs.pop();
		}

Again the program throws up the EXC_BAD_ACCESS at the fprintf function. I think its somethignto do with the way I'm writing/accessing the output file but I have no idea what specifically it can be....
 
So new development. if I reverse the backslash in the output filename to a fowardslash the program runs without throwing an error. However when I go to find the results, the file simply isn't there. Now I know when I run this in visual studio, the file is automatically created and everything is copasetic. Is this not the case on xcode? Do I need to create the file or something?
 
What's your CWD?

Edit: basically, I think you're running the program with a current working directory where you may not have permission to create a file, or isn't where the executable is. Break at the fprintf line and see if output is null, and if not, where the file is.
 
Last edited:
You're absolutely right though I was able to create files there. I am a supreme idiot. It is outputting the file just to the directory the executable is in which is Library/Developer/Xcode/DerivedData/ProjectName/Build/products/debug/file.

Now for my last question...How do change the workign directory to the actual project directory?

Thanks
-Joker
 
Forgive my stupidity because I am an absolute Unix noob. However would I simply chnage the directory? I'm using the GUI to mainly run things, is there an option there where I could change the working directory?
 
Forgive my stupidity because I am an absolute Unix noob. However would I simply chnage the directory? I'm using the GUI to mainly run things, is there an option there where I could change the working directory?

Perhaps I'm not understanding. Do you want to do it programatically or at runtime?
 
I want to be able to do it programmically.

Adding the '~/' leads to a bad access error.

I just want to be able to be able to have a c'string with the file name and for the program to output the file to the directory my project is in. Is there any option for this?
 
I want to be able to do it programmically.

Adding the '~/' leads to a bad access error.

I just want to be able to be able to have a c'string with the file name and for the program to output the file to the directory my project is in. Is there any option for this?

Your project is in, or the executable is in? Have you tried running it from the command line in the folder you want, thus making sure your CWD is as you expect?

And if it's programatically, chdir is the answer you seek.
 
Back
Top