Please can someone help me and show me where i am going wrong ?
The code below is not an assignment or homework
it is something i am tryigng to do for work.
The code scans a text file ( attached ) and stores 10 x 5 digit ints into an array
It then uses a recursive call to search the array for a with a number from stdin
when i run the code and enter a number to search it crashes
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
int numberstore [10];
int num ;
int i =0;
int m,c,l,u,b,n,a;
FILE *inputfile;
inputfile= fopen("numbers.txt","r");
if (inputfile == NULL)
{
printf("error! opening file\n");
exit(0);
}
while (fscanf(inputfile, "%d", &num) > 0) // scan the input file and store items in the array
{
numberstore[i] = num;
i++;
}
fclose(inputfile);
printf("Enter the number to be searched:");
scanf("%d",&m);
l=0,u=n-1;
c=binary(a,n,m,l,u);
if(c==0)
printf("Number is not found.");
else
printf("%d Number is found.",c);
return 0;
}
int binary(int a[],int n,int m,int l,int u){
int mid,c=0;
if(l<=u){
mid=(l+u)/2;
if(m==a[mid]){
c=1;
}
else if(m<a[mid]){
return binary(a,n,m,l,mid-1);
}
else
return binary(a,n,m,mid+1,u);
}
else
return c;
}