我遇到問題,不能告訴它是什麼。從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