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. "From here to maternity",
  9. "The girl from Iwo Jima",
  10. };
  11.  
  12. void find_track(char search_for[]){
  13. int i;
  14.  
  15. for (i = 0; i < 5; i++) {
  16. if ( strstr(tracks[i], search_for) )
  17. printf("Track %i: '%s'\n", i, tracks[i]);
  18. }
  19. }
  20. int main(){
  21. char search_for[80];
  22. printf("Search for: ");
  23. fgets(search_for, 80, stdin);
  24. find_track(search_for);
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 2296KB
stdin
town
stdout
Search for: Track 1: 'Newark, Newark - a wonderful town'