Question: I need help with this question in c. Your program should be implemented in a file named phone.c. The program takes no command line arguments.

I need help with this question in c.

Your program should be implemented in a file named phone.c. The program takes no command line arguments. Instead, it will read one line at a time from standard input until the stream is closed. Each line will contain two elements: a 10 character string and an integer.

If the integer is zero, the program prints the full string to standard output followed by a single newline character. If the integer is between 1 and 9 inclusive the program only prints the corresponding digit from the string to stdout (again followed by a newline). After printing the requested output, the program should read and process the next line from standard input.

Once all of the input has been processed, the program should terminate and return 0.

Hints

No error checking of the input is expected or required. We will only provide lines with a 10 character string, whitespace, and then an integer.

scanf has a return value you may want to check that tells you whether it read data successfully.

To store a string of 10 characters, you actually need to allocate space for 11 characters. The extra space is for a special character that indicates the end of the string.

Test you code by redirecting the contents of a file to it: "./phone < test_file.txt". Fill test_file.txt with appropriately formatted lines of input.

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!