Question: Implement a function that takes two strings as arguments, a and b. It then creates a new string at least as long as both a

Implement a function that takes two strings as arguments, a and b. It then creates a new string at least as long as both a and b. It compares a and b and outputs a new string that indicates how the two strings differ.

Pattern

Output

a[i] == b[i]

c[i] = =

a[i] > b[i]

c[i] = +

a[i] < b[i]

c[i] = -

i > len(a) and i <= len(b)

c[i] = ?

i > len(b) and i <= len(a)

c[i] = ?

Use the following prototype:

char * diff(const char *a, const char *b);

Here are some examples:

Input

Output

diff(aaab,aaac)

===-

diff(bbbbb,cc)

--???

diff(123, 012)

+++

diff(What?,)

?????

You may use functions in string.h.

Hint: you need to use malloc to allocate storage space for the new string, and return a pointer to the new array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!