[ create a new paste ] login | about

Link: http://codepad.org/vqN4wpQp    [ raw code | output | fork ]

C, pasted on Nov 25:
struct result {
int index;
int value;
};

struct result* linear_search(int arr[], int len, int key)
{
int i,j;
struct result *p;
for(i=0;i<len;i++)
{
if(arr[i]==key){
    (*p).index = i;
    (*p).value = arr[i];
    return p;
}
}
    return NULL;
}

main()
{
printf("stRT\n");
struct result *ret;
int arr[]={1,2,4,7,9,10};
int len = sizeof(arr)/sizeof(arr[0]);
ret = linear_search(arr,len, 9);
printf("%d %d",len,ret);
}


Output:
1
Segmentation fault


Create a new paste based on this one


Comments: