Hello! I have been spending the last 3 days trying to work out why my program crashes after trying to search an array.
This happens after using the switch to get to 'Manage>Search Track'. It will display 'Search for which song?', but will then crash, with an error: 'Untitled1.exe has stopped responding'. The lines after this is for a loop to search an array, so I am guessing that the loop could be causing the problem.
Sorry about the amount of code, but I wasn't sure if more than the code above mentioned would be enough.
I would appreciate any help.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <windows.h>//changing font colour
#include <string.h>
typedef struct
{
char track[99];
char trackname[99];
char artist[99];
char genre[99];
} song; //creates a struct called song;
song songs[99];
int main(void)
{
system("color f5");//gives the window a white background (f) and purple text (5)
int menu, option, playchoice, manage, managechoice, end = 0, counter=0, space;
char target, x, asearch;
while(end!=1) //loops switch
{
space = 100 - counter; //space available
printf("\nSpace available: %i%%\n", space);
printf("\nMake a selection:\n");
printf("1=Play\n");
printf("2=Music\n");
printf("3=Manage\n");
printf("4=Four\n");
printf("5=Quit\n");
scanf("%d", &menu );
switch( menu )
{
case 1:
printf("1=Play by song\n");
printf("2=Shuffle\n");
scanf("%d", &playchoice);
switch (playchoice)
{
case 1:
printf("Which song?");
gets(songs[0].trackname);
char buffer[100]; //buffers
sprintf( buffer, "mplayer %s", songs[0].trackname );
system( buffer );
break;
case 2: printf("Shuffle\n\n");
}
break;
case 2:
printf("Music list:\n\n");
for(x=0; x<=3; x++)
printf( "Track: %s Artist: %s Genre: %s\n", songs[x].trackname, songs[x].artist, songs[x].genre);
break;
case 3:
printf("1=Add track\n");
printf("2=Search track\n");
scanf("%d", &managechoice);
switch (managechoice)
{
case 1:
{
if(counter <99)
{
counter++;
printf("Filepath for track to add: \n\n");
gets(songs[counter].trackname); //references to the first record and its first variable
printf("Name of track: \n\n");
gets(songs[counter].trackname);
printf("Artist: \n\n");
gets(songs[counter].artist);
printf("Genre: \n\n");
gets(songs[counter].genre);
}
else if(counter == 99)
printf("You cannot store over 100 tracks");
break;
}
case 2:
{
printf("Search for which song??: \n\n");
scanf("%c", asearch);
int i;
for(i=0;i<99;i++)
{
if(*songs[i].trackname == asearch)
{
printf("found it");
}
}
}
}
// }
break;
case 4:
break;
}
}
return (0);
}