I'm not sure what's going wrong. The data is correct when it's assigned, but after the for loop I try and get the values from the array and they seem totally random. What's going on?Code:int primeGen(a1){ int b1; int b2; b2=0; int b4; int *b5; int b6; b5 = (int *)calloc(a1*2,sizeof(int)); b5[0]=1; b5[1]=2; b5[3]=2; b5[4]=3; for(b1=5; b2 < a1; b1++){ if (checkPrime(b1)) { /* What I'm doing is ordering the array b5 such that entry i*2 is the ith index, and that i*2+1 is the ith prime */ b5[5+b2*2]=3+b2; //These seem to be working fine b5[6+b2*2]=b1; b2++; } } for(b6=0;b6<a1;b6++){ printf("%d %d \n",b5[b6],b5[b6+1]); //But down here the data's all messed up } return 0; }
Thanks