int get_name()
{
char cName[] = "hello";
int iCode, i = 0;
struct sign_in items[6];//array of six structure variables
Fpointin =fopen("namepass.txt","r");
if (Fpointin == NULL)
{
printf ("File does not exist.\n");
}
else
{
for (i=0;i<6;i++)
{
fscanf(Fpointin,"%s %d",items[i].name,items[i].password);//read all values from the file into th structure
}
printf("Here is the sign_in structure\n");//print the entirety of the sign_in structure
for (i=0;i<6;i++)
{
printf("name: %s\ncode: %d\n\n", items[i].name, items[i].password);
}
}
fclose(Fpointin);
}
こんにちは。プロジェクトからコードのこのセクションを取得しましたが、実行しようとするとクラッシュします。ファイルから構造体に名前とそれぞれのパスコードを読み取ろうとしていますが、機能していません。fscanf
行では、識別子%s %d
を交換して実行しましたが、ファイルにあるものとはまったく似ていないランダムなものを出力しました。何か案は?
[コメントからの更新:]
struct sign_in
{
int password; //The password for each player
char name[]; //Name of the people who can sign in
}