Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C, use the following requirements to modify p0.c Only modify p0.c p0.h : int str_length(char *s); int str_isalpha(char *s); void str_copy(char *to, char *from);

In C, use the following requirements to modify p0.c

image text in transcribed

Only modify p0.c

p0.h :

int str_length(char *s); int str_isalpha(char *s); void str_copy(char *to, char *from); void str_censor(char *sp, char *bad); void str_concat(char *base, char *suffix);

p0.c :

#include "p0.h" /* returns the number of characters in the sequence pointed to * by first arg, excluding the null terminator. I.e., * does the same thing as the library function strlen(). */ int str_length(char *s) { /* YOUR CODE HERE */ }

/* returns true (nonzero) iff every character in the sequence * pointed to by sp is a letter of the alphabet (i.e., either * in the range through or through ). */ int str_isalpha(char *s) { /* YOUR CODE HERE */ }

/* copies the contents of the character sequence indicated by from * (including the null terminator) into the space indicated by to. */ void str_copy(char *to, char *from) { /* YOUR CODE HERE */ }

/* modifies the string pointed to by sp by replacing each character * that is in the sequence with a space character . */ void str_censor(char *sp, char *bad) { /* YOUR CODE HERE */ }

/* appends the string pointed to by suffix to the string pointed to by base */ void str_concat(char *base, char *suffix) { /* YOUR CODE HERE */ }

------------------------------------------------------------------------------------------

You can test p0.c using simplep0driver.c :

#include #include "p0.h" /* use quotes for local (non-system) header files */ #define STRBUFLEN 12 int main() { char base[STRBUFLEN]; char suf[STRBUFLEN] = {' ', '2', '7', '0', 0 }; char *test = "test"; char *bad = "t7"; printf("str_length(test) returns %d. ",str_length(test)); printf("str_isalpha(suf) returns %d. ",str_isalpha(suf)); printf("str_length(\"this is a test\") returns %d. ", str_length("this is a test")); printf("str_isalpha(bad) returns %d. ",str_isalpha(bad)); str_copy(base,test); printf("after str_copy, base is %s. ",base); str_concat(base,suf); printf("after str_concat, base is %s. ",base); str_censor(base,bad); printf("after str_censor, base is %s. ",base); return 0; }

A header file p0.h is provided on the canvas page. A template file p0.c is also provided. You will modify the latter file (by replacing the "YOUR CODE HERE" comments with C code) and turn in that modified file and nothing else. Your code must satisfy the following constraints: 1. Self-contained. Your implementations must not call any functions other than those defined in your p0.c file. (If you need auxiliary functions you must define them in p0.c.) The file you turn in (see below) must not have any global variables or additional \# include statements. 2. Your definitions of the functions must exactly match the declarations in p0.h. (This is true of the given p0.c.) 3. Your code must not read past the null terminator of any string. 4. The file contains your implementations of the above functions and nothing else. In particular, it must not contain a main function

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

How to solve maths problems with examples

Answered: 1 week ago