#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#define MLEN 20


struct PET 
{
	char type[MLEN]; // loại thú - tối đa 9 kí tự
	char name[MLEN]; // tên thú - tối đa 9 kí tự
	int HP; // lượng máu
	int attack; // chỉ số công
	int defense; // chỉ số thủ
	int nSkill; // số lượng tuyệt chiêu
	char** skill;
	// mỗi tuyệt chiêu là 1 chuỗi tối đa 19 kí tự
	// lưu thành mảng (cấp phát động)
};
typedef struct PET P;


void Capphat1(P *&DanhSach)
{
	DanhSach = (P *)malloc(sizeof(P));
}
void Capphat2(char **&Skill)
{
	Skill = (char **)calloc(4, sizeof(char));
	for( int i = 0 ; i < 4 ; i++)
		Skill[i] = (char *)calloc(19,sizeof(char));
}
void main()
{
	P *a;
	int soluongthu = 0; // bien nay tang theo cap phat
	FILE *DS = fopen("DanhSachThu.txt","rt");
	while ( !feof(DS) )
	{
		Capphat1(a);
		fscanf(DS , "%s ", a->name);
		fscanf(DS , "%s ", a->type);
		fscanf(DS , "%d ", &a->HP);
		fscanf(DS , "%d ", &a->attack);
		fscanf(DS , "%d ", &a->defense);
		fscanf(DS , "%d ", &a->nSkill);
		Capphat2(a->skill);
	}
	fclose(DS);
	// xuat.
	int i = 0;
	while ( a != NULL)
	{
		printf("%s", a->name);
		printf("\n%s", a->type);
		printf("\n%d", a->HP);
		printf("\n%d", a->attack);
		printf("\n%d", a->defense);
		printf("\n%d", a->nSkill);
		printf("\n%s ", a->skill[i]);
		i++;
		if(i == soluongthu) break;
	}

}