コードを実行しようとすると、最初の入力が要求されますが、次にコアにダンプされたことが示されます。プログラムを実行すると、コアがダンプされる
私はいくつかの疑問がありますが、どうすればそのような警告を修正できますか? Dこれらと
コンパイル:
グラム++ -O2 -Wall -o Proy2.cpp Proy2
そして、このコードを最適化できるなら、私に教えてくださいしてくださいは、I`mは 効率的なコードを作成しようコード:
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
typedef struct PC{
char Brand[20];
char Model[20];
char Serial[20];
char Processor[10];
};
PC PC1[5],*machine;
unsigned int i;
for(i = 0; i < 4; i++){
cout <<"Insert PC brand: ";
fgets(machine->Brand, 20, stdin); fflush(stdin);
cout <<"Insert PC model: ";
fgets(machine->Model, 20, stdin); fflush(stdin);
cout <<"Insert PC serial: ";
fgets(machine->Serial, 20, stdin); fflush(stdin);
cout <<"Insert PC processor: ";
fgets(machine->Processor, 10, stdin); fflush(stdin);
printf("PC Brand : %s", PC1[i].Brand);
printf("PC Model : %s", PC1[i].Model);
printf("PC Serial : %s", PC1[i].Serial);
printf("PC Processor: %s", PC1[i].Processor);
PC1[i] = *machine;
}
return 0;
}
あなたの 'machine'変数は決して初期化されません。もしそれが修正されれば、それを本格的な答えにしてください:) – saloomi2012
"コアはコンパイルしようとしました " - あなたは*コンパイラがクラッシュしたと言っているようです?それは珍しいことです(しかし、聞いたことはありません)。 – immibis
CまたはC++を使用するかどうかを決めてください。 'fgets'は' getline'で、 'fflush(stdin):'は不正です。もちろん、直面する問題を解決するには 'machine = new PC; 'が必要です。 –