これは、以下の私のコードです:構造体の値を印刷機能に渡し、それをメインで呼び出すにはどうすればよいですか? - C言語
enum DifficultyKind
{
Normal,
Hard,
Insane
} DifficultyKind;
typedef struct Target_Data
{
my_string name;
int hit_id;
int dollarvalue;
enum DifficultyKind difficulty;
} Target_Data;
enum DifficultyKind read_difficulty_kind (const char *prompt)
{
int temp;
enum DifficultyKind result;
printf("%s\n", prompt);
printf("\n");
printf("1: Normal Difficulty \n");
printf("\n");
printf("2: Hard Difficulty \n");
printf("\n");
printf("3: Insane Difficulty \n");
printf("\n");
temp = read_integer("Please make a selection between 1 and 3: \n");
if (temp < 1) {
printf("\n");
printf("You did not make a selection between 1 and 3\n");
printf("\n");
temp = read_integer("Please make a selection between 1 and 3: \n");
}
if (temp > 3) {
printf("\n");
printf("You did not make a selection between 1 and 3\n");
printf("\n");
temp = read_integer("Please make a selection between 1 and 3: \n");
}
result = temp - 1;
return result;
}
Target_Data read_target_data (const char *prompt)
{
Target_Data result;
enum DifficultyKind Difficulty;
printf("%s\n", prompt);
result.name = read_string("Enter name: ");
result.hit_id = read_integer("Enter hit ID: ");
if (result.hit_id < 0) {
printf("Please enter a value of 0 or higher \n");
result.hit_id = read_integer("Enter hit ID: ");
}
result.dollarvalue = read_integer("Enter $ value of target: ");
if (result.dollarvalue < 0) {
printf("Please enter a value of 0 or higher \n");
result.dollarvalue = read_integer("Enter $ value of target: ");
}
Difficulty = read_difficulty_kind("Please select the level of difficulty this bounty is from the below options:");
return result;
}
void print_target_data (Target_Data *toPrintData)
{
printf("\nDifficulty: %d, Target: %s, Hit ID: %i, $%i,\n", toPrintData->difficulty, toPrintData->name.str, toPrintData->hit_id, toPrintData->dollarvalue);
}
int main()
{
Target_Data *Target_Data;
read_target_data("Please enter the details of your bounty: ");
print_target_data(&Target_Data);
}
プログラムが実行され、詳細情報を入力した後、私は以下の取得:
Please enter the details of your bounty:
Enter name: Jonathan
Enter hit ID: 10
Enter $ value of target: 500
Please select the level of difficulty this bounty is from the below options:
1: Normal Difficulty
2: Hard Difficulty
3: Insane Difficulty
Please make a selection between 1 and 3:
1
Difficulty: 10, Target: , Hit ID: 0, $0,
私は非常に多くの異なる方法を試してみましたが、すべて見てきました解決策はありますが、実際に何をすべきかはわかりません。
ヒットIDの入力番号として読みにくいのはなぜですか?その他の詳細は表示されません。
BountyHunter.c:96:20: warning: incompatible pointer types passing
'Target_Data **' (aka 'struct Target_Data **') to parameter of type
'Target_Data *' (aka 'struct Target_Data *'); remove &
[-Wincompatible-pointer-types]
print_target_data(&Target_Data);
^~~~~~~~~~~~
BountyHunter.c:87:38: note: passing argument to parameter 'toPrintData' here
void print_target_data (Target_Data *toPrintData)
誰か助けてください。私はそれをコンパイルするとき
これも私が手警告メッセージです!
(より適切に
sscanf
への後続の呼び出しでfgets
への呼び出しであるべき、それはまた別の日である)scanf
に呼び出しをされていますデータを読み込むための構造体を割り当てられていません。構造体型へのポインタを割り当てていますが、初期化していません。あなたは構造体へのポインタへのポインタを、構造体へのポインタを期待する関数に渡します。コンパイラの警告に注意してください。それがあなたに指摘する問題を修正してください。その後、警告レベルを上げてください。 –'name.str'?これは、 'my_string'の型と、コードがどのようにしてコマンドエントリをどのくらい正確に読み込むかに依存します。 – Evert
どこが 'read_target_data'ですか? –