我遇到问题,不能告诉它是什么。从file.txt读取其输入的字符串数组C编程
struct arrayDB {
char *user[MAX_SIZE];
char *pass[MAX_SIZE];
char db[10][2];
};
void readFile(char fileName[100])
{
char* word ;
char line[90];
FILE *passFile;
int rowC=0;
int chk=0;
passFile=fopen(fileName,"rt");
while(fgets(line,90,passFile)!=NULL)
{
word=strtok(line," ");
rowC=rowC+1;
while(word!=NULL)
{
printf("Count=%i \n",rowC);
if(chk==0)
{
printf("word:%s\n",word);
DB.user[rowC]=word;
chk=1;
}
else
{
printf("word:%s\n",word);
DB.pass[rowC]=word;
}
printf("r=%s , c=%s\n",DB.user[rowC],DB.pass[rowC]);
word=strtok(NULL," ");
}
chk=0;
}
int i;
for(i=1; i<6;i++)
{
printf("- %s , %s \n",DB.user[i],DB.pass[i]);
}
}
,但我得到了所有的数组元素的输出是它是文件 中的最后一个字,你可以在PIC看到
感谢
相同的值
放置截图而不是文本复制/粘贴真的更容易吗? –
您显示的代码不是您运行该示例的代码。首先,在行DB.pass [rowC] = word;没有定义''DB'。 – ryyker