can't seem to see my error here, when I compile and run I just get the "Search for: " coming up, I enter something that should show a result but nothing happens and just exits.
I've recreated this code exactly(from what I can see!) from the Head First C book but it's not working the same, theirs appears to show the results when you search for it.
So hit me up guys, what have I done wrong? Thanks in advance!!
Btw, arrays + array pointers do my head in lol.
Here's the code:
#include <stdio.h>
#include <string.h>
char tracks[][80] =
{
"I left my heart in Harvard Med School",
"Newark, Newark - A wonderful town",
"Dancing with a Dork",
"From here to maternity",
"The girl from Iwo Jima",
};
void find_track(char search_for[])
{
int i;
for (i = 0; i < 5; i++)
{
if (strstr(tracks[i], search_for))
printf("Track %i: '%s'\n", i, tracks[i]);
}
}
int main()
{
char search_for[80];
printf("Search for: ");
fgets(search_for, 80, stdin);
find_track(search_for);
return 0;
}