its just one difference ...i saw that calloc inicialize all elements to 0 so i put that...and what you said about loop to N-1..i put it and its still problem...
Code:
#include<stdio.h>
#include<stdlib.h>
int main() {
int *p=NULL,N,v,b,i=0;
printf("Enter number of elements array:");
scanf("%d",&N);
p=(int *)calloc(N,sizeof(int)); // inicijalizira sve na 1 za razliku od malloc
if(p==NULL) {
printf("Out of memory");
exit(1);
}
for(b=2;b<=N-1;b++) {
v=b;
if(*(p+v)==0) {
printf("%d ", b);
for (i=2;v<=N-1;i++) {
v=b*i; /* 2 3 4 5 6 7 8 9 10 11 ... n */
*(p+v)=1; }
}
}
free(p);
printf("\n\nEnd"); /* this i put here just to see if compiler will go to this point,compile will not print this,he just shows message "stop working" before he go to this line */
getch();
return 0;
}