Question: In C NOT C++ : Write the following functions, consistent with the prototypes shown: int strlen(char* s); Given a string, return the number of characters

In C NOT C++ : Write the following functions, consistent with the prototypes shown:

int strlen(char* s); Given a string, return the number of characters in the string, NOT INCLUDING the null at the end.

char* strcpy(char* dest, const char* src); The function will copy the string src into the string dest. Note the function returns the address of the string dest.

char* strcat(char* dest, const char* src); The function concatenates the string src into the end of string dest. If dest is "Hello " and src is "World" before, after calling strcat, dest will be "Hello World"

Important:

Do NOT use the C library routines.

Do implement the functions EXACTLY as prototyped (i.e., no extra parameters, no fewer parameters, etc.)

You may use the functions as "building blocks".

Write main() functions to test and debug each of the above string functions, using gets() and puts() for string input and output as follows:

To demonstrate strlen(), input your first name using gets() and use printf to print the string followed by the number of characters in the string. An input of "Ken" would print 3. Show this with 3 different string input examples.

To demonstrate strcpy(), input your first name using gets(s1) and use strcpy() to copy it to a second string, s2 and print both strings with puts(). So an input of "Ken" would print: "string1 = Ken string2 = Ken".

To demonstrate strcat(), use gets() to input your first name, last name, and Red ID as three separate strings, print them out, one per line, concatenate the three strings, and then use puts() to print out Hello followed by your name and Red ID. If the three input strings entered are "Tim" "Ronaldo" and "123456789", then it should print:

Tim Ronaldo 123456789 Hello Tim Ronaldo 123456789 

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!