fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char tracks[][80] = {
  5. "I left my heart in Harvard Med School",
  6. "Newark, Newark - a wonderful town",
  7. "Dancing with a Dork",
  8. "The girl from Iwo Jima",
  9. };
  10.  
  11. void find_track(char search_for[]) {
  12. search_for[strcspn(search_for, "\n")] = 0;
  13. for (int i = 0; i < 5; i++) if (strstr(tracks[i], search_for)) printf("Track %i: '%s'\n", i, tracks[i]);
  14. }
  15.  
  16. int main() {
  17. char search_for[80];
  18. printf("Search for: ");
  19. fgets(search_for, 80, stdin);
  20. find_track(search_for);
  21. }
  22.  
  23. //https://pt.stackoverflow.com/q/106706/101
Success #stdin #stdout 0s 4400KB
stdin
Iwo
stdout
Search for: Track 3: 'The girl from Iwo Jima'