所以基本上我想讀一個文本文件,其中包含代表和拍賣的數字,有多少物品正在銷售,有多少商品以及實際商品。我必須做的是輸出最高報價作爲售價,但由於某種原因,我的計劃只打印出最後價格而不是最高價格。我的輸出是Wonky
#include <stdio.h>
//main function
int main() {
//Declaring variables and arrays
float numberBids[15], max, sum = 0 ,numberAuc;
float bids[10];
int i, y, j= 0, x, z = 0;
char filename[100]= "";
//User puts in filename
printf("Please enter the name of the file.\n");
scanf("%s",&filename);
//Opens file
FILE * finp=fopen(filename,"r");
//Scans info
fscanf(finp, "%f" , &numberAuc);
for(i=0; i < numberAuc; i++){
fscanf(finp, "%f",&numberBids[i]);
for (x = 0; x < numberBids[i];x++)
{
fscanf(finp, "%f", &bids[i]);
max = bids[i];
}
//Replaces old max with newer one if larger
for(j; j<numberBids; j++)
if (bids[i]>max)
max = bids[i];
}
//Sum
sum += bids[i];
//Print out to the output
for (y = 0; y < numberAuc; y++)
{
y = y+ 1;
printf("Auction %d was sold for $%.2f\n", y, bids[z]);
z++;
y = y- 1;
}
//Close
fclose(finp);
return 0;
}
而且這裏是文本文件說
5
4
100 500 250 300
1
700
3
300 150 175
2
920 680
8
20 10 15 25 50 30 19 23