#include <stdio.h>
#include <stdlib.h>
#include <time.h> //乱数の生成のため
//構造体の宣言(いじらない)
typedef struct {
char na[64];
int stts[6];
} Monster;
//ランダムにモンスターを生成(いじらない)
Monster creMonster(){
int i,k;
Monster tmp;
for(i
=0;i
<k
;i
++) tmp.
na[i
] = 'a' + rand()%26; tmp.na[k] = '\0';
for(i
=0;i
<6;i
++) tmp.
stts[i
] = rand()%255+1; return tmp;
}
//モンスターの情報を表示する関数(修正)
void priMonster(Monster m){
// ステータスの名前を配列で保持
const char* status_names[] = {
"攻撃力", "防御力", "素早さ", "体力", "知力", "幸運"
};
printf("名前:%12s \nステータス \n", m.
na);
// ステータスの名前と値を表示
for(int i = 0; i < 6; i++) {
printf("%s:%3d\n", status_names
[i
], m.
stts[i
]); }
}
int main(){
srand((unsigned)time(NULL
)); //乱数を生成する時のおまじない int i, n;
Monster *monsters;
monsters
= (Monster
*)malloc(sizeof(Monster
)*n
);
// 以下はいじらなくてOK
if(monsters == NULL){
return 0;
}
for(i = 0; i < n; i++){
monsters[i] = creMonster();
priMonster(monsters[i]);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4gLy/kubHmlbDjga7nlJ/miJDjga7jgZ/jgoEKCi8v5qeL6YCg5L2T44Gu5a6j6KiA77yI44GE44GY44KJ44Gq44GE77yJCnR5cGVkZWYgc3RydWN0IHsKICAgIGNoYXIgbmFbNjRdOwogICAgaW50IHN0dHNbNl07Cn0gTW9uc3RlcjsKCi8v44Op44Oz44OA44Og44Gr44Oi44Oz44K544K/44O844KS55Sf5oiQ77yI44GE44GY44KJ44Gq44GE77yJCk1vbnN0ZXIgY3JlTW9uc3RlcigpewogICAgaW50IGksazsKICAgIE1vbnN0ZXIgdG1wOwogICAgayA9IHJhbmQoKSU4KzQ7CiAgICBpbnQgYSA9ICdhJyArIHJhbmQoKSUyNjsKICAgIGZvcihpPTA7aTxrO2krKykgdG1wLm5hW2ldID0gJ2EnICsgcmFuZCgpJTI2OwogICAgdG1wLm5hW2tdID0gJ1wwJzsKICAgIGZvcihpPTA7aTw2O2krKykgdG1wLnN0dHNbaV0gPSByYW5kKCklMjU1KzE7CiAgICByZXR1cm4gdG1wOwp9CgovL+ODouODs+OCueOCv+ODvOOBruaDheWgseOCkuihqOekuuOBmeOCi+mWouaVsO+8iOS/ruato++8iQp2b2lkIHByaU1vbnN0ZXIoTW9uc3RlciBtKXsKICAgIC8vIOOCueODhuODvOOCv+OCueOBruWQjeWJjeOCkumFjeWIl+OBp+S/neaMgQogICAgY29uc3QgY2hhciogc3RhdHVzX25hbWVzW10gPSB7CiAgICAgICAgIuaUu+aSg+WKmyIsICLpmLLlvqHlipsiLCAi57Sg5pep44GVIiwgIuS9k+WKmyIsICLnn6XlipsiLCAi5bm46YGLIgogICAgfTsKICAgIAogICAgcHJpbnRmKCLlkI3liY3vvJolMTJzIFxu44K544OG44O844K/44K5ICBcbiIsIG0ubmEpOwogICAgCiAgICAvLyDjgrnjg4bjg7zjgr/jgrnjga7lkI3liY3jgajlgKTjgpLooajnpLoKICAgIGZvcihpbnQgaSA9IDA7IGkgPCA2OyBpKyspIHsKICAgICAgICBwcmludGYoIiVz77yaJTNkXG4iLCBzdGF0dXNfbmFtZXNbaV0sIG0uc3R0c1tpXSk7CiAgICB9Cn0KCmludCBtYWluKCl7CiAgICBzcmFuZCgodW5zaWduZWQpdGltZShOVUxMKSk7IC8v5Lmx5pWw44KS55Sf5oiQ44GZ44KL5pmC44Gu44GK44G+44GY44Gq44GECiAgICBpbnQgaSwgbjsKICAgIE1vbnN0ZXIgKm1vbnN0ZXJzOwogICAgcHJpbnRmKCJhIiksCiAgICBzY2FuZigiJWQiLCAmbik7CiAgICBtb25zdGVycyA9IChNb25zdGVyICopbWFsbG9jKHNpemVvZihNb25zdGVyKSpuKTsKICAgIAogICAgLy8g5Lul5LiL44Gv44GE44GY44KJ44Gq44GP44GmT0sKICAgIGlmKG1vbnN0ZXJzID09IE5VTEwpewogICAgICAgIHByaW50ZigiRVJST1JcbiIpOwogICAgICAgIHJldHVybiAwOwogICAgfQogICAgCiAgICBmb3IoaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgIG1vbnN0ZXJzW2ldID0gY3JlTW9uc3RlcigpOwogICAgICAgIHByaW50ZigiJTAzZCAgIiwgaSArIDEpOwogICAgICAgIHByaU1vbnN0ZXIobW9uc3RlcnNbaV0pOwogICAgfQogICAgCiAgICBmcmVlKG1vbnN0ZXJzKTsKICAgIHJldHVybiAwOwp9Cg==