Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. # Reads in an Album from a file and then prints all the album
  2. # to the terminal
  3.  
  4. def main
  5. music_file = File.new("album.txt", "r")
  6. album = read_album(music_file)
  7. music_file.close()
  8.  
  9. search_string = read_string("Enter the track name you wish to find: ")
  10. index = search_for_track_name(album.tracks, search_string)
  11. if index > -1
  12. puts "Found " + album.tracks[index].name + " at " + index.to_s
  13. else
  14. puts "Entry not Found"
  15. end
  16.  
  17. end
  18. main
  19.  
  20. def search_for_track_name(tracks, search_string)
  21. index = 0
  22. count = music_file.gets()
  23. while (index < count)
  24. if (tracks[index] == search_string)
  25. return found_index = -1
  26. end
  27. index += 1
  28. end
  29. found_index
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement