Question: input_names.txt is a file containing names. The first line is the total number of names containing in this file, this number won't exceed 100. From

input_names.txt is a file containing names. The first line is the total number of names containing in this file, this number won't exceed 100. From second line, each line has a name followed by a comma. Write a program which reads in all the names with the comma from this file to an array called names. If there exists same name, numbering the repeated names. Then write the updated names to a file called output_names.txt in the same format as input_names.txt

example input_names.txt 12 John, Mary, Frank, Dave, David, Mary, John, Robert, Linda, Mary, Emma, Emma,

output_names.txt 12 John, Mary, Frank, Dave, David, Mary2, John2, Robert, Linda, Mary3, Emma, Emma2,

Hint: Store all names in an array. For each name, have a counter, go through all the names to find duplicated names, then update by insert the counter value into the string. Alternatively, while writing the names to the file, have a counter find out how many times each name has appeared before currently, write both the name and counter to the new file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!