Here's description for code below. For the input sequence of numbers from 1 to 3000 my code stops at 1040 input. I can't understand why it is happening. Please help!!
#include<stdio.h>   
#include<stdlib.h>
void search(int x,int *array,int a,int b,int *c)
{
  for(int i=b+1;*(array+i)<=x;i++)
  {
      if(*(array+i)==x)
      {
        *c=1;
        printf("%d %d %d\n",*(array+b),x,(*(array+b)+x));
        return;
      }
  }
}
int main()
{
  int t,n,i=1,j,sum,flag;
  scanf("%d",&t);
  getchar();
  while(i<=t)
  {
    flag=0;
    scanf("%d",&n);
    printf("%d\n",n);
    getchar();
    int *array=(int *)malloc(n*sizeof(int));
    for(j=0;j<n;j++)
    {
        scanf("%d",(array+j));
        getchar();
        printf("%d\n",*(array+j));
    }
    scanf("%d",&sum);
    getchar();
    for(j=0;*(array+j)<=(sum/2);j++)
    {
        search((sum-*(array+j)),array,n,j,&flag);
    }
    if(flag==0)
    {
        printf("-1\n");
    }
    i++;
  }
}
 
    