Question: C program that inputs lines from files where each line is in the following format: rank Male name Male number Female name Female number where,
C program that inputs lines from files where each line is in the following format:
rank Male name Male number Female name Female number
where,
rank The ranking of the names on this line Male name A male name of this rank
Male number Number of males with this name Female name A female name of this rank Female number Number of females of this rank
This is the format of database files obtained from the U.S. Social Security Administration of the top 1000 registered baby names (https://www.ssa.gov/OACT/babynames/index.html). Each line begins with the rank, followed by the male name at that rank, followed by the number of males with that name, etc. Here is a part of an example file containing data from the year 2017. You may assume the fields are tab separated.
1 Liam 18728 Emma 19738
2 Noah 18326 Olivia 18632
3 William 14904 Ava 15902
4 James 14232 Isabella 15100
5 Logan 13974 Sophia 14831
...
... ...
As you can see from the above, in 2017, there were 18728 male babies named Liam and 19738 female babies named Emma, making them the most popular names used in that year in U.S.
Your program will be given one or more filenames as commandline arguments that contain popular names from different years. The filenames will be in the form namesYYYY.txt where YYYY denote the year the data is from. E.g. names1998.txt will contain data from 1998.
Your program should read in the data from the input files and store in an appropriate array of structures. You should define an appropriate structure to store information related to a specific name. For example a structure may look like this (add additional members you you need them)
struct popularName {
char *name;
int rank;
int number;
char type; // M or F for male or female
};
All arrays and strings must be dynamically allocated. For example, the member name in above structure must contain the address of a dynamically allocated string (just large enough to contain the input name, not any larger.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
