I'm currently practicing on struct, and here is my simple code. I'm currently having a problem here that I couldn't find the answer. My code asks me to type a song's name, its artist and duration of the song. I typed "My Lightning Speed", but only the word "My" fills the song's name. The word "Lightning" fill the artist and Speed fills the duration. Why? How can I fix it?
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdio.h>
#define SIZE 20
typedef struct {
char name[SIZE];
char artist[SIZE];
int duration;
} songname;
songname FillSong();
int main()
{
songname songNumb1, songNumb2, songNumb3;
songNumb1 = FillSong();
songNumb2 = FillSong();
return 0;
}
songname FillSong()
{
songname tempC;
printf("\n");
printf("Enter the name of this song: ");
scanf(" %s", tempC.name);
printf("name: %s\n", tempC.name);
printf("Who is the artist? ");
scanf(" %s", tempC.artist);
printf("artist: %s\n", tempC.artist);
printf("What is the duration(seconds)? ");
scanf("%d", &tempC.duration);
printf("duration: %d\n", tempC.duration);
return tempC;
}