Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that a character (or char) represents things like a, Z and (that last one is a new line character). If you make an array

Recall that a character (or char) represents things like a, Z and (that last one is a new line character). If you make an array of characters ending with a \0, you have a text string. We will look at this soon. In the meantime, lets act like an array of chars is like any other array. Write a function replaceAllCh that takes 4 parameters: 1) a_chars, an array of characters that you will modify

2) numChars, the length of array a_chars 3) oldChar, a char to search for 4) newChar, a char to replace toFind with The function will return the number of old characters that are replaced by the new character. The function prototype will look like this: unsigned int replaceAllCh(char* a_chars, unsigned int numChars, char oldChar, char newChar); Example Calls: char a_chExample[] = { 'a', 'b', 'a', 'b', 'a', 'c', '\0' };

assert(replaceAllCh(a_chExample, 7, 'a', 'b') == 3); // The array is now {b, b, b, b, b, c, \0}

assert(replaceAllCh(a_chExample, 7, 'a', 'b') == 0); // T he array doesn t change. No a to remove assert(replaceAllCh(a_chExample, 7, 'b', '~') == 5); // The array is now {~, ~, ~, ~, ~, c, \0}

printf("The new character array is %s ", a_chExample);

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

Step: 3

blur-text-image

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago