write to .csv files??

I am attempting to output with fprintf within C++ in Xcode on Mac for the purposes of Physics project. Previously I have used Turbo C++ on a PC and had no issues with similar outputs as as I wrote up below... I am trying to send data to a .csv file in order to create graphs/charts in xcel, but the debugger HATES the output I attempting. Can someone PLEASE help me and tell me how to send output out of xcode and into either xcel or mac's numbers program? What is wrong with my code? THANKS I AM AT MY WIT'S END!

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

int main ()
{ int ia,ja,ib=1,jb=1,n=1,t=1;
float Ia[25],Ja[25],C[25][25],Wbb[25][25],xl[25][25],xr[25][25],Pr[25][25],Nr[25][25],max,r1,H=0;

max=RAND_MAX;
FILE * Project1;
Project1 = fopen (“Users/Dave/Desktop/Project1.csv”,”w”);

Ia[n]=3;
Ja[n]=3;
for(t=1;t<100;++t) //time step counter
{
n=1;
for(n=1;n<26;++n) //# of states to look at
{
ia=Ia[n];
ja=Ja[n];
ib=1;


for(ib=1;ib<6;++ib) //determine I[n]'s C[ia][ja] values (initially will be the same due to ICs)
{
jb=1;
for(jb=1;jb<6;++jb)
{
C[ia][ja]=100*(ia-ib)^2+100*(ja-jb)^2+1;
}
}
//fprintf(Project1, "%d,%d,%d,%f\n",n,ia,ja,C[ia][ja]);


ib=1;
for(ib=1;ib<6;++ib) //determine Wsrs and delta x's for each system I[n] {
{
jb=1;
for(jb=1;jb<6;++jb)
{
Wbb[ib][jb]=C[ia][ja]/((100)*(ia-ib)^2+100*(ja-jb)^2+1);
xl[1][1]=0;
xr[ib][jb]=xl[ib][jb]+Wbb[ib][jb];
//fprintf(Project1,"%d,%d,%f,%f,%f",ib,jb,Wbb[ib][jb],xl[ib][jb],xr[ib][jb]);
xl[ib][jb+1]=xr[ib][jb];
}
}


r1=rand()/max; //randomly select new state and determine it's ib,jb value and reassign to new ia, ja at next time step
ib=1;
for(ib=1;ib<6;++ib)
{
jb=1;
for(jb=1;jb<6;++jb)
{
if(r1<xr[ib][jb] & r1>xl[ib][jb])
Nr[ib][jb]++;
Ia[n]=ib;
Ja[n]=jb;
}
}
}

ib=1;
for(ib=1;ib<6;++ib)
{
jb=1;
for(jb=1;jb<6;++jb)
{
Pr[ib][jb]=Nr[ib][jb]/25;
H=Pr[ib][jb]*log(Pr[ib][jb])+H; //Compute Total Entropy Function of all systems by adding each systems entropy
}
}

//fprintf(Project1,"%f",H); //print out the Entropy at each time step
}
}
What do you mean by 'hate'? If the environment thinks there's a problem, it'll tell you. You can't just ignore the actual message if you ask for help.
As kbw says: Please describe the error more precisely.

Your program seems to be fully Posix compliant, standard C program - and so runnable on MacOSX. You don't need <iostream> here.

But value the value for ia becomes really bad (-2147483648). So after 26 times assigning to C[ia][ja] generates a segmentation fault. Some debuggers (maybe the one used by Turbo C++?) awkwardly initializes all allocated bytes of memory with the value 0. This will hide some coding errors. Xcode's debugger correctly doesn't force NULL initializing fresh allocated memory areas.

BTW: Xcode doesn't interpret your program. It's just an IDE. Like most IDEs it uses an external debugger, which also doesn't interpret your code.

LAST: Please use code tags (use this little button marked '<>' at the right of the editor area of this page) when reporting your code to this forum.
Topic archived. No new replies allowed.