If you enter 1 for the first id, 2 for the password, 3 for the second, 4 for the password, 5 for the last destination, and 6 for the d, the results are all displayed as 5 and 6.
I'd appreciate your help.
I wonder that the output values are all 5 and 6. ( You must write a pointer inside the structure. )
void game(struct gameInfo *login, char *id, char *password) {
printf("game dts: ");
fgets(id, sizeof id, stdin);
login->dts = id;
cl(login->dts);
printf("game password: ");
fgets(password, sizeof password, stdin);
login->password = password;
cl(login->password);
}
void printGame(struct gameInfo *login) {
for (int i = 1; i < 4; i++) {
printf("%d %35s %35s\n", i, (login + i)->dts, (login + i)->password);
login++;
}
}
int main(void) {
for (int i = 1; i < 4; i++) {
gameInfo(login + i, id, password);
printf("(login + i)-> dst, (login + i)->password);
login++;
}
}