Skip to content

Instantly share code, notes, and snippets.

@mb6ockatf
Last active February 11, 2024 14:10
Show Gist options
  • Save mb6ockatf/a42ae1ff5d25f159836ca48bb90e997e to your computer and use it in GitHub Desktop.
Save mb6ockatf/a42ae1ff5d25f159836ca48bb90e997e to your computer and use it in GitHub Desktop.
strstr does not work properly
#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 main(void);
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(void){
char search_for[80];
printf("Search for: ");
fgets(search_for, 80, stdin);
find_track(search_for);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment