我不明白:停止原因= EXC_BAD_ACCESS(代码= 1,地址= 0x400)?

时间:2015-09-20 05:10:08

标签: c debugging exc-bad-access

错误指向一行中没有任何内容的行。我以为我是在制作 链接列表不正确,但我不确定发生了什么。该文件是否可能已损坏,或者这是否与内存分配和内存指针有关,因为我不确定我的双向链表方法是否可靠。谢谢您的帮助。 '

        #define EXTERN
        #include "header.h"
        #include <stdlib.h>
        #include <stdio.h>
        #include <math.h>
        int main(int argc, char *argv[]) {

            int N; 
            //int oddsonly = (BITS_PER_SEG*2) - 1; 
            int NSegs;
            int numOfPrimes;

            if (argc == 2) sscanf(argv[1],"%d",&N);
                else scanf("%d",&N);
                NSegs = (int)ceil(  ((N-3 )/(float)odds_only)  );
                printf("This is the number of segments made: %d\n", NSegs);
            //this is how we make a doubly linked list 
            //void makelinkedlist(){
            //this is how we make a doubly linked list 
            //void makelinkedlist(){
            int i; 
            seg *node; 
            seg *current;
            //head = (seg*)malloc(sizeof(seg));
            head = NULL;
            for(i = 0; i <= NSegs; i++ ) { 
                if(i == 0) {
                    node = malloc(sizeof(seg)); 
                    node->prev = NULL; 
                    node->next = NULL;
                    head = node;
                }//if
                else{
                    //current = malloc(sizeof(seg)); 
                    current = head; 

                    while(current->next != NULL){
            current = current->next; 
        }
                    }//while
                    current->next = malloc(sizeof(seg)); 
                    node = current->next; 
                    node->prev = current; 
                    node->next = NULL; 
                    //head = head;   
                    }//else
                }//for


           printf("Done allocating %d nodes\n",i);  


           sieveOfE( N );    // Modify my solution in C project 1 !!!

           numOfPrimes = countPrimes( N );

           printf("Number of primes found = %d\n", numOfPrimes );

         //  if ( numOfPrimes <= 3000 ) 
           //   printPrimes( N );

           // void decompostion(int N){
           //   int sums; 
           //   int L = 3;
           //   int R = N-L; 
           //   int keepL;
           //   int keepR; 
           //   while(L <= (N/2)){
           //       if(!testIsBit0(L) & !testIsBit0(R)){
           //           keepL = L;
           //           keepR = R;
           //           sums++;
           //       }
           //       L= L+2; 
           //       R = R-2; 
           //   }
           //   printf("%d = %d + %d out of %d solutions \n",N, keepL, keepR, count );
           // }


           printf("Done.\n");
        }

我收到了这个: enter image description here

enter image description here

0 个答案:

没有答案