rendered paste body#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int * a;
int main(int argc, char * argv[])
{
FILE * fptr;
int c;
int i;
int count = 0;
int found =0;
int key;
int sptr;
fptr = fopen(argv[1], "r");
do
{c = fgetc(fptr);
if ( c == '\n')
{count++;}
}
while (c != EOF);
//printf("count:%d", count);
a = malloc(sizeof(int)*count);
//sptr = a; //holding start point position
fclose(fptr);
int low =0;
int high = count;
int middle = (low+high)/2;
fptr = fopen(argv[1], "r");
//c = fgetc(fptr)
for(i=0;i<count;i++)
{
fscanf(fptr, "%d", &a[i]);
//printf("value is:%i\n", a[i]);
}
printf("enter compare number here\n");
scanf("%d", &key);
do{
//printf("\nhigh:%d\nmiddle:%d\nlow:%d\n", high, middle, low);
//printf("\nhigh number:%d\nmiddle number:%d\nlow number:%d\n", a[high], a[middle], a[low]);
printf("\n");
for (i=low; i<high+1; i++)
{printf("%d ", a[i]);}
if(a[middle]==key)
{printf("\nThe value %d is located at index %d\n", a[middle], middle);
found =1;}
else if(a[middle]>key)
{high = (middle-1);
middle = (low+high)/2;}
else
{low = (middle +1);
middle = (low+high)/2;}
}
while (found != 1);
return EXIT_SUCCESS;
}