Once again we will be working with a list of names that includes everyone in our class, BUT this time each person's name has embedded in the middle a secret number, so each line in the file looks like:

Jasson18791Aguilera

Notice that there are no spaces separating the names or the numbers. The program that you write is to read in every line of the file "namesnum.txt" and to separate the secret number from each of the names, and then to print it at the end of the two names, with a space separating the names. So the output file, called secretnums.txt, will look something like:

Jasson Aguilera 18791

And now the real fun. If we all work together we can open up the vault, and the key that opens the vault is actually the sum of everyone's secret numbers.

The method:

Read a line into a single string

Using two counters walk through that string, copying one character at a time into the first name string until you reach a digit (For this you can use the isdigit function from ctype.h - it takes a single char argument (e.g. isdigit(fullname[j]);) and returns truthfulness.)

Put the '\0' at the end of the string you have built.

Reset one of your counters and copy all the characters to another string in a loop, until you encounter a non-digit. Put the '\0' at the end of the string you have built.

Reset one of the counters and copy all the characters to the end of the original string into still another string. Put the '\0' at the end of the string you have built.

Use the function atoi, which takes a single string as an argument, and returns the integer represented by that string to extract the number from the second string you constructed. This function is in stdlib.h.

Add that number to a sum.

Output the strings and the number for each student to a file, with the number following the name. At the bottom output the secret number.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.