from your function drawpoints
:
int* counter; //You don't allocate memory for this int
double x,y,dist; /*coordinates of point*/
int* n = arg
*counter = 0; //yet here you assign 0 to a unknown memory location
So before you dereference counter you have to run something like this:
int* counter = malloc(sizeof(int));
and check whether couter != NULL.
Also than you need to make sure you free it as well after use.