Question: C++ Write a function called c StringManip that demonstrates the following functions by writing code that performs that function ( NOTE: cString variables should be
C++
Write a function called cStringManip that demonstrates the following functions by writing code that performs that function (NOTE: cString variables should be declared as character arrays, not strings):
Enter in a string called testString. Display the string and its length by using strlen.
Enter in a first name and a last name into two separate strings. Copy the first name into a string called fullName using strcpy. Display that string and its length.
Add the last name to fullName using strcat. Display the fullName and the length. Note: make sure that there is a space between the first and last names.
Enter in a string called city.
Copy the contents of city into a string called fullAddress using strncpy. Copy only the actual number of elements in the string up to a max of 10 characters. The max value should be a constant.
NOTE: Remember, strncpy and strncat does NOT add a null terminator if the number of characters added is less the size of the string. So, make sure to add a null terminator if necessary!!
Compare the string city with the fullAddress string using strcmp. Display an output that states that the strings match or do not match based on the outcome.
Enter in two more strings (state and zip). Add them to fullAddress using strncat. Again, only concatenate the max number of characters. Display the output of the full address (should be in the format: Columbia, Maryland 21044)
Search for the state in the fullAddress string using strstr. Display the resulting string when the state is found.
NOTE: Remember, strstr returns a pointer. So there needs to be a pointer variable created to hold this pointer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
