我知道我的问题已经被其他人问过了,但是作为 C 的初学者,
坦率地说,我不理解这些问题的答案。
我目前使用的是 Windows,我的代码是 C(我使用的是 VS2012)
这是我的文本文件的内容:
Bulwark Fury // Assign this string into player.name
Red Steel // Assign this string into player.title
230 // Assign this string into player.typenclass
21 // Assign this string into player.startstr
2.9 // Assign this string into player.incstr
16 // Assign this string into player.startdex
1.6 // Assign this string into player.incdex
16 // Assign this string into player.startintel
1.7 // Assign this string into player.incintel
44 // Assign this string into player.basemindmg
60 // Assign this string into player.basemaxdmg
1.7 // Assign this string into player.baseattacktime
1.24 // Assign this string into player.basearmor
代码:
typedef struct nodebase
{
char name[20],title[20],type[15],Class[15];
int typenclass;
int startstr;
double incstr;
int startdex;
double incdex;
int startintel;
double incintel;
int basemindmg,basemaxdmg;
double baseattacktime;
double basearmor;
struct nodebase *next;
struct nodebase *curr;
struct nodebase *prev;
}herostat;
static void stat_file(const char *file_name, herostat player)
{
FILE *f = fopen(file_name, "r");// open the specified file
if (f != NULL)
{
int c;
while ((c = fgetc(f)) != EOF)// read character from file until EOF
{
fscanf(f,"%s\n%s\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n",
&player.name, &player.title, &player.typenclass,
&player.startstr, &player.incstr, &player.startdex,
&player.incdex, &player.startintel, &player.incintel,
&player.basemindmg, &player.basemaxdmg,
&player.baseattacktime, &player.basearmor);
}
fclose(f);
}
}
我尝试运行它并打印变量只是为了确保 fscanf 运行良好,
但是当打印的是一些随机数......
请帮忙!