I am getting an error Abnormal program termination when I execute this code.
The objective the program is read array of numbers from file list.txt
and perform recursive binary and recursive linear search on that loaded array.
Here is my code:
#include <stdio.h>
#include <conio.h>
void menu();
int a[30000],n;
void main()
{
FILE *fp;
int i, ch;
fp = fopen("list.txt", "r");
if(fp == NULL)
{
printf("\nCant read\n");
exit(0);
}
for(i = 0; i < n; i++)
fscanf(fp, "%d", &a[i]);
fclose(fp);
for(i = 0; i < n; i++)
printf(" %d ", a[i]);
menu();
scanf("%d", &ch);
if(ch == 1)
{
printf("ch1\n");
}
else if(ch == 2)
{
printf("ch2\n");
}
else
{
exit(1);
}
}//end main
void menu()
{
printf("\nEnter the number of elements in array\n");
scanf("%d", &n);
printf("\n1.Linear Search\n2.Binary Search\n3.Exit\nEnter your choice\n");
}
I have the logic for my choice 1 and 2. I need to know whats wrong with my above code. Please help me out in this