Basically I'm creating a program that will output the number if it is found in an given array or output -1 if not found. (Sorted Array.)
#include <stdio.h>
#include <stdlib.h>
int cmp(const void*a,const void *b){
    if(*(int*)a-*(int*)b>0) return 1;
    if(*(int*)a-*(int*)b<0) return -1;
    return 0;
}
int main() {
    int n; scanf("%d",&n);
    int a[n];
    for(int i =0;i<n;i++) 
        scanf("%d",a+i);
    for(int i =0;i<n;i++){
        int *item;
        item = (int*)bsearch(&i,a,n,sizeof(int),cmp);
        if(item!=NULL) printf("%d ",i);
        else printf("-1 "); 
    }
    return 0;
}
INPUT : 10
-1 -1 6 1 9 3 2 -1 4 -1
OUTPUT :
-1 1 2 3 4 -1 6 -1 -1 9
My OUTPUT :
-1 -1 -1 3 4 -1 -1 -1 -1 -1
 
     
    