Question: PLEASE IN C Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs. You will write 2

PLEASE IN C

Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs.

You will write 2 functions which resemble functions in the cstring library. But they will be your own versions:

int cstrcat(char dst[], char src[]) which concatenates the char array src[] to char array dst[], and returns the new length of the dst[], not counting the null terminator character. You may assume dst[] was declared large enough to handle the combined length. Write the loops to find the end of the first string and to do the copy. DO NOT make calls to C-string library functions.

int cstrcmp(char s[], char t[]) which compares the char array s[] to char array t[], and returns 1 if the strings are identical, and zero otherwise. Write the loop to do the compare;' DO NOT make calls to C-string library functions. Be sure you don't compare past the end of either string.

Your main() program should:

(1) Prompt the user to enter 2 strings, and save into 2 char[40] arrays using fgets(). Assume the user will enter less than 40 characters for each string. NOTE THAT YOUR PROGRAM WILL HAVE TO REMOVE THE NEWLINE CHARACTER FROM THE END OF EACH STRING, as fgets() puts the newline in the string as its last character. You can do that by overwriting the newline char, which is at index strlen(stringname)-1, with '\0' Ex:

Enter 2 strings on separate lines: Hello, world! Hello there. 

(2) Use the cstrcmp() function to determine if they are equal, and print out a statement (1pt): Ex:

The strings are NOT equal. 

(3) Call the cstrcat() function to append the 2nd string to the first, then print out the new longer string and its length (1 pt): Ex:

Concatenated string: Hello, world!Hello there. Length: 25 

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!