Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a C program. The screenshots are the green boxes. Please use the guidelines on the red box and try to get a sample

This is a C program. The screenshots are the green boxes. Please use the guidelines on the red box and try to get a sample output like the one in the picture.

Exercise 1 (50 points): Write your own versions of the strlen and strncat functions described in the text. (See the screenshot of the function descriptions given below. figure 8.14 and 8.33) Write a function named removechr that removes all occurrences of the specified character from a string. All three of these functions will use pointers and pointer arithmetic. (You may not use array subscripts anywhere in your functions.)

Your removechr function will be prototyped as follows:

char *removechr(char *string, const char ch);

The function removechr removes all occurrences of a character from a string and returns a pointer to the modified string. Please note it does modify the string that is its first argument and it is case sensitive. (T is treated differently than t.)

image text in transcribed

Sample output of a driver used to test removechr produced the following results:

image text in transcribed

You may NOT call anything from the library in your functions.

You may test your strlen and strncat functions by comparing the results produced with those produced by the library versions. You will need to create a driver to test your functions.

We will be testing your functions with our driver. We will NOT be including the string.h header file in our program. Again your functions must work without using anything from the library! The required files are 3 codes one each with strlen, strncat and removechar.

GUIDELINES

image text in transcribed

Fig. 8.14 String-manipulation functions of the string-handling library Function Function description prototype char stropy char s1, const char s2) Copies string s2 into array s1. The value of s1 is returned char strncpy (char 1, const char s2, size_t n) Copies at most n characters of string s2 into array s1 and returns s1 char strcat (char s1, const char s2) Appends string s2 to array s1. The first character of s2 overwrites the terminating null character of s1. The value of s1 is returned. char strncat(char 1, const char s2, size t n) Appends at most n characters of string s2 to array 1. The first character of s2 overwrites the terminating null character of s1. of s1 is returned. The value Fig. 8.33 Other functions of the string-handling library. Function Function description prototype char "strerror (int errornum) Maps errornum into a full text string in a compiler- and locale-specific manner (e.g. the message may appear in different spoken languages based on the computer's locale). A pointer to the string is returned. Error numbers are defined in errno.h size t strlen(const char): Determines the length of string s. The number of characters preceding the terminating null character is returned

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

More Books

Students also viewed these Databases questions

Question

3. Is there opportunity to improve current circumstances? How so?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago