Basically I'm trying to read from a text file which I created. I have a header of value 5, indicating that the rest of the file contains the data for 5 separate auctions.
The next line contains a value of 4, indicating 4 bids in the first auction. The four integers after that represent bids in the auction. Here's the entire text file:
5
4
80 70 100 270
2
8 7
1
800
7
90 81 72 685 49 50
4
800 900 785 600
Basically, I need to figure out the largest of the bid values for each auction. I can probably do that on my own, but I'm really stuck when it comes to representing those bid values as an array.
Here's my code so far:
#include <stdio.h>
int main()
{
int header, i, j, cur_val, auction[cur_val];
FILE *ifp;
ifp = fopen("input.txt", "r");
fscanf(ifp, "%d", &header);
for (i = 0; i < header; i++) {
fscanf(ifp, "%d", &cur_val);
printf("%d\n", cur_val);
for (j = 0; j < cur_val; j++) {
fscanf(ifp, "%d", &auction[cur_val]);
printf("%d\n", auction[cur_val]);
}
printf("\n");
}
//printf("Auction %d was sold for ");
fclose(ifp);
return 0;
}
If I create auction without the array then it prints the values but I have no way of accessing each individual value in order to determine the max value. How can I get the "bidding" values to act as an array of values? Using this code just crashes my entire program.