/* This program demonstrates two topics that you will have to implement in your coding assignments as well: 1. reading from files that have a specific format 2. "formatted printing" - printing integers in a way that can produce 'aligned' rows by reserving 4 spaces for every number printed. See: printf("%4d|", nums[i]); */ #include #include int linear_search(int nums[], int N, int val); int binary_search (int nums[], int left, int right, int val); int main(){ char fname[100]; int mx_size, N, i, M, val; FILE *fp; printf("Enter the filename: "); scanf("%s", fname); fp =fopen(fname, "r"); if (fp == NULL){ printf("File could not be opened.\n"); return 1; } fscanf(fp, "%d %d", &mx_size, &N); int nums1[mx_size]; //int* nums1 = malloc(mx_size * sizeof(int)); // read from file and populate array for (i = 0; i < N; i++) { fscanf(fp, "%d ", &nums1[i]); //printf("%4d|", nums1[i]); } int found = linear_search(nums1, N, 67); printf("\nreturned index:%d\n", found); // read the second line of numbers from file and search for them in nums1 fscanf(fp, "%d", &M); for(i=0; i