割り当てに問題があります。ファイルから構造体を読み込み、ここでどのように行うのか混乱しています。使用するパラメータがある関数です。複数のファイルから構造体を読み込む
// This function will read in size struct players from filename and add these
// the players array. The function will use index to know where to start
// writing the players to in the array.
// Parameters
//
// filename – The name of the input file
// players – a pointer to the array of player structures
// index – The index of the array to start placing players into
// size – The number of players in the input file
// Return - Nothing
void read_from_file(char* filename, Player* players, int index, int size);
これは私のような見て、3種類のファイルからデータを読み込むために使用しなければならない機能です:
Andrew Jackson 129 33 38 30 506
Jeremy Warden 25 24 3 9 493
Jared Welch 130 1 43 27 422
Brandon Splitter 138 38 40 7 587
Joe Gwilliams 150 23 30 25 498
Ali Mohammed 119 43 13 6 598
Dheeraj Johnson 124 79 59 36 506
Bill Clinton 121 65 12 26 449
Jesse James 87 58 8 5 464
John Doe 129 100 0 12 548
私はすべてのためにそれらに10人の選手を持っている3つのファイルを読み込む必要はあり合計30の構造を読み込む必要があります。私は非常に遠くまで私は知っていないが、私は何をすべきか、どのようにこれにアプローチするのが非常に混乱している、どんな助けも非常に高く評価されるだろう!下に私はすでに行っていることをダウンしている。助けてください!!おかげ
//Brady Webb
//lab D
//HW1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct player
{
char Fname[25];
char Lname[25];
int Singles;
int Doubles;
int Triples;
int Homeruns;
int At_Bats;
float Slugging_Percentage;
} Player;
void read_from_file(char* filename, Player* players, int index, int size);
int main(int argc, char* argv[])
{
int size= atoi(*(argv+1));
char* file1 = *(argv+2);
char* file2 = *(argv+3);
char* file3 = *(argv+4);
if (argc<6 || argc>6)
{
printf("Incorrect command line arguments\n");
return 0;
}
return 0;
}
void read_from_file(char*filename, Player* players, int index, int size)
{
FILE *ptr;
int i=0;
if ((ptr=fopen(filename, "r")) == NULL)
{
return 0;
}
while (ptr != EOF)
{
}
}
「argv + 5」についてはどうですか? argv + 1から得られる値の意味は? 'if(argc!= 6)' – user3629249
エラーメッセージは 'stdout'ではなく' stderr'に出力されなければなりません。次の行は 'if(argc <6 || argc> 6)です。したがって、次の行: 'printf("不正なコマンドライン引数\ n ");'は、実際には 'fprintf(stderr、"不正なコマンドライン引数\ n ");' – user3629249
プログラムに属していない場合は、 'argc' FIRSTの値をチェックし、有効な場合にのみ個々の引数を取得します。 – user3629249