Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions