Question: Update the code below that will input three c-strings and printed those that began with yan or ended with es using loops and c-string functions.

Update the code below that will input three c-strings and printed those that began with "yan" or ended with "es" using loops and c-string functions. Modify it so string objects are used instead of c-strings. Input three strings (that could contain spaces) into an array of strings. Again use a function to first find the length for the end comparisons, then you can again compare the last two characters separately with a string function. Then use a string function to take a sub-string of the first three characters for the beginning comparison all at once. Use separate for loops to input and go through the array.

#include

#include

using namespace std; int main() { char **arr = new char*[3]; cout << "Enter 3 strings: "; for (int i = 0; i < 3; ++i) { arr[i] = new char[1000]; cin >> arr[i]; } cout << endl << "strings starting with yan and ending with es are" << endl; for (int i = 0; i < 3; ++i) { int len = strlen(arr[i]); if (strncmp(arr[i], "yan", 3) == 0 && arr[i][len - 1] == 's' && arr[i][len - 2] == 'e') { cout << arr[i] << endl; } } return 0; }

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!