Question: Q1. Write a C program that asks the user to enter a string, a start index and an end index. The program should print the

 Q1. Write a C program that asks the user to entera string, a start index and an end index. The program shouldprint the substring that starts at the start index in the user's

Q1. Write a C program that asks the user to enter a string, a start index and an end index. The program should print the substring that starts at the start index in the user's string and ends at the end index in the user's string. Your program must check that the start index is less than or equal to the end index and that both indices are non-negative. If the user enters invalid indices, the program should print a message prompting the user to try again. In addition, if the user enters the same index twice, the program should print only the character in the string at that index. Your program must use fgets() to input the user's string, not scanf(). For this exercise, you do not need to check if either of the indices exceed the length of the string. Sample output #1: Welcome! Please enter a string: C was developed by Dennis Ritchie Now, enter the substring start index: 19 Now, enter the substring end index: 24 Your substring is "Dennis" Sample output #2: Welcome! Please enter a string: C was developed by Dennis Ritchie Now, enter the substring start index: 8 Now, enter the substring end index: 3 Invalid indices! Try again. Now, enter the substring start index: 0 Now, enter the substring end index: -2 Invalid indices! Try again. Now, enter the substring start index: 26 Now, enter the substring end index: 26 Your substring is "R

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!