C++ only use #include #include using namespace std; 2. Write a function named “isValidCString” that

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

C++ only use #include #include using namespace std; 2. Write a function named “isValidCString” that

Post by answerhappygod »

C++ only use #include <iostream>#include <string>using namespace std;
2. Write a function named “isValidCString” that accepts an arrayof characters and its size.It will return true if that array is a correct C-string and falseotherwise.
The requirement is that you cannot use any string function suchas strlen or string class and its method. This is an exercise on pointers and you are required to do thecheck by examining each character in the array using pointers.
This function works with an array of characters and not stringclass.Please use only pointer notation. Please do not use or refer thestring class in this function.
The following arrays will return true char s0[] = {'0', '\0'} ; char s1[] = {'1', '0', '\0'} ; char s2[] = {'1', 'b', '\0'} ; char s3[] = {'1', '0', '1', '0', '\0'} ; char s4[] = {'1', '0', '1', '0', 'b', '\0'} ;
And the following arrays will return false char s5[] = {'\0', ' '} ; char s6[] = {'b', '\0', 'b'} ; char s7[] = {'1', 'b', '0', '\0', '0'} ; char s8[] = {'0'} ;
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply