Question: 2. Write a function named hasOnlyLeadingOrTrailingBlanks that accepts a C-string (an array of characters with a NULL terminating character) and returns true if that C-string
2. Write a function named "hasOnlyLeadingOrTrailingBlanks" that accepts a C-string (an array of characters with a NULL terminating character) and returns true if that C-string contains a string that may have only leading and trailing blanks but there is no blank in the middle of the string.
For example, "", " ", "123456", " 123456", "123456 " or " 123456 " will return true. "123 456", " 123 456", "123 456 ", or " 123 456 " will return false. Please note that an empty or blank only C-string will return true.
The requirement is that you cannot use any string function such as strlen. You are required to do the check by examining each character in the C-string and performing the validity check in the function.
This function works with C-string (an array) and not the string class. It means that you should not pass the size of the C-string to the function as a parameter. Please use only pointer notation. Please do not use or refer the string class in this function. It is not allowed to go over the array multiple times. You should be able to determine the outcome with only one iteration.
Please write in C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
