C 练习 bool 类型分段错误

C exercise bool type segmentation fault

I Don't know Why But this code give me a Segmentation Fault,I'm trying to understand , this exercise Basically check if the numbers insert by user in the first array(A) Has some Zero and Duplicate numbers, and if that is true, The program will not insert that zero and duplicate in the next array (B).

   #include <stdio.h>
#include <stdbool.h> 

 int main () {
int a[19], b[19], i, j, N, A = 0;
  
  do{
      printf ("How many numbers? : ");
      scanf("%d", &N);
    }while (N > 19);
  
 for(i=0;i<N;i++)
    {
      printf ("Insert the number %d : ", i + 1);
      scanf ("%d", &a[i]);
}
for(i=0;i<N;i++){
    
    bool zero= false;
    bool idem= false;
    
 for(j=0;j<N;i++){
    if(a[i]==a[j])
        idem= true;
      if(a[i]==0)
        zero= true;
    }
    if(idem==false){
    b[A]=a[i];
    A++;
    }
    if (zero== false){
    b[A] = a[i];
    A++;
    }
    
 for (i=0;i<A;i++){
        printf ("%d", b[i]);
}

 }
 
}

那是你的内循环 for(j=0;ji++) 你必须增加 j 而不是 i。这样 for(j=0;jj++){

如果你递增 i 你将超过数组长度导致发生分段错误

#include <stdio.h>
#include <stdbool.h> 
  int main () {
  int a[19], b[19], i, j, N, A = 0;
  bool idem,zero;
  //Input number of elements
  do{
    printf ("How many numbers? : ");
    scanf("%d", &N);
  }while (N > 19);
  //Input array
  for(i=0;i<N;i++){
    printf ("Insert the number %d : ", i + 1);
    scanf ("%d", &a[i]);
  }

  //Checking duplicates and zeroes
  for(i=0;i<N;i++){ //for
    zero= false;
    idem= false;
      
  for(j=0;j<N;j++){
      if(a[i]==a[j]&&i!=j){  //add a condition (&& means AND). if j=i obviusly a[i]  = a [j]
        printf("idem found\n"); //printf debug
        idem= true;}
  }
  if(a[i]==0){
    printf("zero found\n"); //printf debug
    zero= true;}
      
    //a[i] mustn't be either duplicated nor zero. Not only one of this conditions.
    //Use the logical AND &&
    if(idem==false && zero==false){ 
    b[A]=a[i];
    A++;
    }
  }
     
  //output array
  //Must be collocated outside the "main for". I don't need to make an output in every iteration.
  printf("The B array is:\n");
    for (i=0;i<A;i++){
    printf (" %d ", b[i]);
  }
  printf("\n");

  
 
}