sorting structured array problem
Hey guys, I am developing a program that receives song input(artist, title, rating) from the user and inserts that into a structured array. The user will then be prompted to sort the array by artist, title or rating. It complies but when i run this is what happens.
Quote:
How many songs will be entered?2
Enter the information below for songs:
Artist:Title:james
Rating(0-5) :1
Enter the information below for songs:
Artist:Title: peter
Rating(0-5) :2
Select the operation to perform --(t)itle,(a)rtist,(r)ating,(f)ilter,(q)uit:
Select the operation to perform --(t)itle,(a)rtist,(r)ating,(f)ilter,(q)uit:
It skips 'artist' input and just puts in title. Then it shows the 'select the operation to perform' print twice.
here is the main of the program
Code:
int main(void)
{
int i;
int j = 0;
int rating_filter;
char oper;
song oneSong[99];
int songCount;
printf("How many songs will be entered?");
scanf("%d", &songCount);
for(i = 0; i <= songCount - 1; i++)
{
printf("Enter the information below for songs:\n");
printf("Artist:\n");
fgets(oneSong[i].artist, 40, stdin);
printf("Title:\n");
fgets(oneSong[i].title, 60, stdin);
printf("Rating(0-5):");
scanf("%d", &oneSong[i].rating);
}
while(13 == 13)
{
printf("Select the operation to perform --(t)itle,(a)rtist,(r)ating,(f)ilter,(q)uit");
scanf("%c", &oper);
if(oper == 't')
{
printf("Songs by title:\n");
song_by_title(oneSong, songCount);
for(j = 0; j <= songCount; j++)
{
printf("<%s--%s--%d>\n",oneSong[j].title, oneSong[j].artist, oneSong[j].rating);
}
}
else if(oper == 'a')
{
printf("Song by artists:\n");
song_by_artist(oneSong, songCount);
for(j = 0; j <= songCount; j++)
{
printf("<%s--%s--%d>\n",oneSong[j].title,oneSong[j].artist,oneSong[j].rating);
}
}
else if(oper == 'r')
{
printf("Songs by ratings:\n");
song_by_artist(oneSong, songCount);
for(j = 0; j <= songCount; j++)
{
printf("<%s--%s--%d>\n",oneSong[i].title, oneSong[i].artist,oneSong[i].rating);
}
}
else if(oper == 'f')
{
printf("Enter the rating to show:\n");
scanf("%d", &rating_filter);
song_by_title(oneSong, songCount);
for(j = 0; j <= songCount; j++)
{
printf("<%s--%s--%d>\n",oneSong[i].title, oneSong[i].artist,oneSong[i].rating);
}
}
else if(oper == 'q')
{
printf("Thank you for using!\n");
break;
}
j = 0;
}
return 0;
}
help would be greatly appreciated!! Thanks in advanced
-Spencer