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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started