Here's a C program that prints out a string after passing it a sub-string(like a search). The code runs successfully and as intended if i use 'scanf' to collect the sub-string, but abnormally if i use 'fgets', please i would love to know why, thank you for your time.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char track[][80] = {"I left my heart in Havard Med School",
"Newark, Newark - a wonderful town",
"Dancing with a Dork",
"From here to maternity",
"The girl from Iwo Jima",
};
void find_song(char *search)
{
for(int i = 0; i < 5; i++){
if(strstr(track[i], search))
printf("Track %i: %s\n\n", i, track[i]);
}
}
int main(){
char search[80];
printf("search track: ");
//fgets(search, 80, stdin); initial line the book used
scanf("%79s", search); // my line
find_song(search);
}