Question: My output is almost correct but its wrong. #include search.h #include / / #include / / typedef struct { int sought _ index; int

My output is almost correct but its wrong.
#include "search.h"
#include //
#include //
typedef struct {
int sought_index;
int found_value;
int found_index;
} Match;
int read_sought_values(FILE *file, int sought_values[]){
int value, count =0;
while (fscanf(file,"%d", &value)==1 && value >=0 && count MAX_SOUGHT_VALUES){
sought_values[count++]= value;
}
return count;
}
void process_search_space(FILE *file, int sought_values[], int sought_count, FILE *output_file){
int search_space[1000];
int value, search_size =0;
while (fscanf(file,"%d", &value)==1 && value >=0){
search_space[search_size++]= value;
}
fprintf(output_file, "Searching file for matches for %d values.
", sought_count);
fprintf(output_file, "Searched at Searching Found at
");
fprintf(output_file, "-------------------------------
");
Match *matches = malloc(search_size * sizeof(Match));
if (!matches){
fprintf(stderr, "Memory allocation failed
");
exit(EXIT_FAILURE);
}
int match_count =0;
for (int i =0; i sought_count; i++){
for (int j =0; j search_size; j++){
if (search_space[j]== sought_values[i]){
matches[match_count].sought_index = i;
matches[match_count].found_value = sought_values[i];
matches[match_count].found_index = j;
match_count++;
}
}
}
for (int i =0; i match_count; i++){
fprintf(output_file, "%5d %2d %2d
",
matches[i].sought_index, matches[i].found_value, matches[i].found_index);
}
fprintf(output_file, "Number of items searched through in list: %d
", search_size);
free(matches);
}
Wrong: Searching file for matches for 10 values.
Searched at Searching Found at
Number of items searched through in list: 22
Correct: Searching file for matches for 10 values.
Searched at Searching Found at
My output is almost correct but its wrong.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!