I'm getting a segmentation fault:11 after I run the code. I'm new to programming and not sure what the fault is. Any help would be appreciated.
My code is:
Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
//main function
int main() {
int i, x;
int num_bids;
int num_auctions;
float bid;
float max;
float sum = 0;
//open input file
FILE * ifp = fopen("/Users/ninagonzalez/Desktop/COP3223/bids.txt" , "r");
//open output file
FILE * ofp = fopen("/Users/ngonzalez/Desktop/output.txt" , "w");
//scan in info
fscanf(ifp, "%d" , &num_auctions);
for(i=0; i<num_auctions; i++){
fscanf(ifp, "%d",&num_bids);
for (x = 0; x < num_bids;x++)
{
fscanf(ifp, "%d", &num_bids);
max = bid;
}
for(i=1; i<num_auctions; i++)
if (bid>max)
max = bid;
}
max=0;
//sum
sum += bid;
// print out to the output
fprintf(ofp,"Auction 1 was sold for $%.2f\n", bid);
fprintf(ofp,"Auction 2 was sold for $%.2f\n", bid);
fprintf(ofp,"Auction 3 was sold for $%.2f\n", bid);
fprintf(ofp,"Auction 4 was sold for $%.2f\n", bid);
fprintf(ofp,"Auction 5 was sold for $%.2f\n", bid);
fprintf(ofp, "The total made for charity is $%.2f ", bid);
// close
fclose(ifp);
fclose(ofp);
return 0;
}