所以我正在尝试编写一个程序,让我使用双向链表数据结构读取用户输入的 MP3 文件中的数据。我得到了大部分方法和功能,但是当我提示用户输入时,它会在用户输入第一行之前打印出两行。所以例如
int main()
{
int user_input = 0;
while(!(user_input >= 4))
{
struct MP3_data_node* MP3_data;
MP3_data = (struct MP3_data_node*)malloc(sizeof(struct MP3_data_node));
printf("\nPlease select a number for one of the following instructions:\n");
printf("0: add to list\n1: delete from list\n2: print the list from beginning to end\n3: print the list from end to beginning\n4: exit\n");
scanf("%d", &user_input);
if(user_input == 0)
{
printf("Please provide the artist:");
fgets(MP3_data->artist,50,stdin);
printf("Please provide the album:");
fgets(MP3_data->artist,50,stdin);
printf("Please provide the song title:");
fgets(MP3_data->artist,50,stdin);
printf("Please provide the year the song was released: ");
scanf("%d", &MP3_data->yearReleased);
printf("Please provide the length of the song in seconds: ");
scanf("%d", &MP3_data->runTime);
addToList(MP3_data);
}
...
所以它打印出“请提供艺术家:请提供专辑:”然后让我输入输入,所以我的问题是如何让它打印:请提供艺术家:(用户输入)请提供专辑:(用户输入)等