Subj : Re: thread stopped To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Mon Sep 22 2003 10:42 pm cory wrote: >I also get a standard error message on my screen that the file hydro3.txt can't be >opened. I programmed this message into my code. Look at the documentation for fopen(). It tells you how to find out the cause of the non-opening. >-- I get an error "Thread stopped. Fault: access violation at >0x426440: read of address 0xffffffff" >I don't know what the run time error message means. It means, if you look in the CPU mode of the Debugger, at address 0x426440, you will see the code that generated the error. The cause will either be right there, before it, or elsewhere that set up the error-waiting-to-happen. In this particular case, it's likely cause by the fprintf() on the invalid fp because the file couldn't be opened. > I have checked to make sure that the data I am writing is good, > but if I remove the subroutine convect, evrything works fine. Ideas? Could be something wrong with convect() but you didn't show that. > D = dvector(0,N+1); > rho = dvector(0,N+1); > dx = initial(D, rho, phi, E_field, m, E, N); >for (j=1;j<=200;j++) >{ > if ((fp = fopen("hydro2.txt","w")) == NULL) > fprintf(stderr, "Error opening file % > s.", "hydro2.txt"); Hmmm.. you write to fp even if you can't open it...... You might want to break the for(j) loop on error. You need to handle the open-error better, including reporting why it fails. I think "i" goes too high in all these "for" loops. Probably meant i<=N; If N+1 is the number of doubles in the vector, then the index values go from 0 to N not N+1; > for (i=0; i <= N+1 ; ++i ) > fprintf(fp, "%-e\t%-e\t%-e\t%-e\t%-e\n\n",rho[i], m[i], > E[i], phi[i], E_field[i]); > fclose(fp); .