Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

language is in C. Exercise 3.21. String manipulation functions are often vulnerable to ill- formed C strings: character arrays that lack string terminators. For example,

image text in transcribedlanguage is in C.

Exercise 3.21. String manipulation functions are often vulnerable to ill- formed C strings: character arrays that lack string terminators. For example, if copyString of Exercise 3.19 is given an ill-formed string as in, it will read and write through memory until a 0 is found or until a segmentation fault occurs. Write a protected version of copyString that transfers at most n - 1 characters from in to out and always writes a string terminator to out. * 1/* Copies at most n-1 characters of string in into the 2 * buffer pointed to by out. If n is reached, returns -2. 3 * Otherwise, returns -1 for malformed input and O upon 4 * successful completion. * * 6 int copyStringN (char * in, char * out, int n); Implement a unit test of copyStringN in a main function that exercises its full protective functionality

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions