开发者

C: EXC_BAD_ACCESS error

I am trying to run this program to extract some data however I can't get it to work prop开发者_开发技巧erly as I get the error : EXC_BAD_ACCESS.

Here is part of the C program where the error is occurring:

*The line where the error occurs is -

 if ( ( iend = oclread() ) == -1 ) printf(" END OF FILE REACHED\n");

which is located at the bottom.

========================================================================

define maxtax 30  
define maxsec 100  
define maxbio 50  
define maxparm 100  
define maxpsec 25 * maxparm  
define idim 360  
define jdim 180  
define kdim 33  
define kdimax 40  
define maxchoice 8

FILE *fp,*fpout,*fplist, *fpwoa;

char cc[2];

int icruise=0, ostation=0, year=0, month=0, day=0;

int hour,longitude,latitude;

int levels,isoor,nparm,ip2[maxparm],iperror[maxparm];  
int htotfig[3],hsigfig[3],hrightfig[3];

int origcfig,origsfig;
char origc[30],origs[30];
int ipip[maxparm],ipi[maxparm],npi;

int nsec;
int stotfig[maxsec],ssigfig[maxsec],srightfig[maxsec];
int seccode[maxsec],secval[maxsec];

int npsec;
int pstotfig[maxpsec],pssigfig[maxpsec],psrightfig[maxpsec];
int psecparm[maxpsec],pseccode[maxpsec],psecval[maxpsec];

int nbio;
int btotfig[maxbio],bsigfig[maxbio],brightfig[maxbio];
int biocode[maxbio],bioval[maxbio];

int ntsets;
int *ntloc,*ntcode,*ntval,*nterr,*ntoerr,*nttotfig,*ntsigfig,*ntrightfig;

int *depth,*zerr,*zoerr,*ztotfig,*zsigfig,*zrightfig;

int *dataval,*derr,*doerr,*dtotfig,*dsigfig,*drightfig;

int isize,zsize;
int ntsetsmax=0, isizemax=0,zsizemax=0;

double tenp[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
                  100000000 };

int sdepth[] = { 0, 10, 20, 30, 50, 75, 100, 125, 150, 200, 250,  
                 300, 400, 500, 600, 700, 800, 900, 1000, 1100,  
                 1200, 1300, 1400, 1500, 1750, 2000, 2500, 3000,  
                 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000,  
                 7500, 8000, 8500, 9000 }; 

 char *namevar[] = { "Temp","Sal","Oxy","Phos","dum5","Sil","dum7",  
                     "NO3","pH","dum10","Chl","dum12","dum13","dum14",  
                     "dum15","dum16","Alk","dum18","dum19","pCO2",  
                     "DIC","BAC","dum25","dum26","dum27","dum28",  
                     "dum29","dum30","dum31","dum32","Trit","He",  
                     "dHE3","dC14","dC13","Arg","Neo","CFC11",  
                     "CFC12","CFC113","O18" };  

  main()
  {
      char filename[80];
      int i=0, j, k, s, jchoice, iend=0;
      int ncast=0;

      printf(" Enter input file name\n");
      scanf("%s",filename);

      if ((fp = fopen(filename,"rb+\0")) == NULL)
      printf("UNABLE TO OPEN FILE\n");

      else {

            printf( "Which variable would you like to see:\n");  
            printf( " 1 - Temperature\n");  
            printf( " 2 - Salinity\n");  
            printf( " 3 - Oxygen\n");  
            printf( " 4 - Phosphate\n");  
            printf( " 6 - Silicate\n");  
            printf( " 8 - Nitrate\n");  
            printf( "11 - Chlorophyll\n");  
            printf( "17 - Alkalinity\n");  
            printf( "20 - pCO2\n");  
            printf( "21 - tCO2\n");  
            printf( "24 - BAC\n");  
            printf( "33 - Tritium\n");  
            printf( "34 - Helium\n");  
            printf( "35 - deltaHE3\n");  
            printf( "36 - deltaC14\n");  
            printf( "37 - deltaC13\n");  
            printf( "38 - Argon\n");  
            printf( "39 - Neon\n");  
            printf( "40 - CFC11\n");   
            printf( "41 - CFC12\n");  
            printf( "42 - CFC113\n");  
            printf( "43 - Oxy18\n");  
            scanf("%d",&jchoice);

/********************************************************

 INITIALIZE DYNAMIC ARRAYS

*********************************************************/

            spacer(1);

  /*   GET USER INFORMATION (NUMBER OF CASTS, OUTPUT FILE NAME) */

            printf(" Enter output file name\n");
            scanf("%s",filename);

            if ((fpout = fopen(filename,"w\0")) == NULL) 
               {
                 printf("UNABLE TO OPEN FILE\n");
               }

            printf(" ENTER NUMBER OF CASTS TO VIEW");
            printf (" (0 FOR ALL CASTS IN FILE)\n");
            if ( (s = scanf("%d",&ncast)) == 0 ) ncast=0;

            if ( ncast == 0 ) ncast=100000000;

/********************************************************

ENTER STANDARD LEVEL DEPTHS, IN CASE THIS IS STANDARD LEVEL DATA

********************************************************/

            for ( j = 0; j < 40; j++ ) *(depth+j)= *(sdepth+j);

            printheader(jchoice);

            while ( !feof(fp) && (i++) < ncast ) 
            {
             if ( ( iend = oclread() ) == -1 ) printf(" END OF FILE REACHED\n");

             else printstation(i,jchoice);
            }

      }

} 

PLease can someone explain the problem as I really need get this done this.

Thanks


Is this to do with reading data from the World Ocean Database?

If so there's a sample here of how to use oclread(): http://2bitbrain.blogspot.com/2010/08/sqlite3-and-world-ocean-database.html

It looks like you will need to #include the header file that prototypes oclread() and call it with appropriate parameters, namely a WOD_Reader * that you have created and set up.

Does your current code compile and link without errors or warnings?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜