fork(1) 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++) {
  14. if (strstr(tracks[i], search_for)) {
  15. printf("Track %i: '%s'\n", i, tracks[i]);
  16. }
  17. }
  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. return 0;
  26. }
Success #stdin #stdout 0s 2116KB
stdin
Iwo
stdout
Search for: Track 3: 'The girl from Iwo Jima'