Your task this week is to write a program to assist a biologist to tally their counts of migrating whales.
As pods of migrating whales swim past the biologist types the number and species of whales.
Here is an example of the input the biologist will provide
15 humpbacks
3 killer whales
2 sperm whales
19 belugas
2 humpbacks
2 sperm whales
7 killer whales
4 pygmy right whales
7 humpbacks
You will notice the biologists enters one line of input for each pod. Each line contains first the number of whales in the pod followed by the species of whales.
When the end of input is reached the program then must print a tally of how many of each species of whale were seen. For the above input, it should print:
24 humpbacks
10 killer whales
4 sperm whales
19 belugas
4 pygmy right whales
Notice, tallies of species are listed in the order they were first seen.
Write a C program, whales.c, which reads input in the above format and prints output as indicated.
The thing is, even though I put a boundary on the loop for fgets my compiler scans forever. Also, I am concerned about the logic of my coding, I had a little trouble with it and will be happy if it's correct, thanks for your time and help.
The above would allow you to stop the entry by signaling end of file by using CTRL-Z, or CTRL-D depending on what operating system you are using. It'll also stop after 10 entries.