【发布时间】:2021-01-22 11:38:16
【问题描述】:
struct soundInput{
char choice[16];
char type[7];
char sound[10];
char sound2[10];
};
struct soundInput Sound;
FILE *read;
read=fopen("input.txt","r");
fscanf(read,"%s\n",Sound.choice);
printf(Sound.choice);
fscanf 函数从文件中读取数据但只读取 1 行。然后打印过程停止。它只在屏幕上写一行。但是,有超过 20 行。我该如何解决这个错误?
【问题讨论】:
-
等5分钟我给你密码
-
'%s"格式说明符在第一个空格处停止。如果您想阅读更多内容,请使用循环或其他方法。此外,您还需要使用"%15s"来避免缓冲区溢出。 -
fgets 正在读取所有数据。我需要的是在 3 个单独的部分中连续读取 3 条数据。