hi
i need to allocate a "dynamic array". the user can enter the size of it (eg: myprog 100) and this array will be generatet and worked with as a range checker (i'm checking numbers in files and if they alreadi ocured, i'll set array[i]. so if the number comes twice, i can abort). this array is in a function, which will be called several times. si i thought, the folowing thing will do:
Code:
static int initstat;
static int *colision=NULL;
colision=(int *)malloc(max_testnr*sizeof(int));
//initialise
if(initstat == FALSE){
while(i<=max_testnr)
colision[i++] = 0;
}
//some code
//checker routine
if(curent < max_testnr && curent >= 0){ //check range
if(colision[curent] != 0) /* check if already exists */
fputc('*',f2); //mark
else {
fputc(' ',f2);
colision[curent] = 1;
}
}
else
fprintf(f2,"AOR: ");
fputs(nr,f2);
//more code
however, it seems that colision[i] does not work. if i chose a static array everything is fine. what's wrong?
thanks