Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Stage 2 - the encodeStr routine The method signature is shown below: void encodeStr( const char *strin, char *strout, int shift ); This routine accepts

image text in transcribed

Stage 2 - the encodeStr routine The method signature is shown below: void encodeStr( const char *strin, char *strout, int shift ); This routine accepts a constant input string strin, encodes each character in this string by calling the encodechar() function you wrote earlier using the value shift, and then stores the results in strout. Note that you can encode characters until the end of the array, or until you reach a NUL character whichever comes first. You should assume the the two strings have the same length. Please skim this tutorial about C strings, but pay close attention to the "Safe Programming" section: https://www.cprogramming.com/tutorial/c/lesson9.html. If you want to know why this matters, read the page linked to in that section ("a major problem"): https://www.cprogramming.com/tutorial/secure.html. In order for your encodeStr( routine to be fault-tolerant and safe, you will need to iterate over the input character array until either the NUL character is encountered or you reach the end of the character array whichever comes first. You therefore need to know how long the array is. Because there is no way in C to know how many elements are in an array that is a formal parameter to a function, you will have to tell it how long the array is. You could pass in the length of the array as another input parameter to the function, but for the sake of gaining experience with global variables, you will do it differently for this lab. Above all functions, define a constant, global variable called MAX_STRING_SIZE of an appropriate type and make it large enough to contain all strings you expect to enter for this program. (Too small, and some strings won't fit. Too large, and you waste memory.) Assume that the character arrays in your encodeStr() routine are at most this size. Write a main() routine to test your encodeStr() routine. You should declare two character arrays of size MAX_STRING_SIZE: one as an input to your routine and one as the output. Define a variable called shift and pass it to the encodeStr() routine along with the two strings. For your test, initialize the input string to whatever you want to encode. Then, output the input string and the output string, each surrounded by double quotes to mark the beginning and the end of the string. Test the following strings using several values of shift, including positive, negative and zero values: "Hello, World!" Stage 2 - the encodeStr routine The method signature is shown below: void encodeStr( const char *strin, char *strout, int shift ); This routine accepts a constant input string strin, encodes each character in this string by calling the encodechar() function you wrote earlier using the value shift, and then stores the results in strout. Note that you can encode characters until the end of the array, or until you reach a NUL character whichever comes first. You should assume the the two strings have the same length. Please skim this tutorial about C strings, but pay close attention to the "Safe Programming" section: https://www.cprogramming.com/tutorial/c/lesson9.html. If you want to know why this matters, read the page linked to in that section ("a major problem"): https://www.cprogramming.com/tutorial/secure.html. In order for your encodeStr( routine to be fault-tolerant and safe, you will need to iterate over the input character array until either the NUL character is encountered or you reach the end of the character array whichever comes first. You therefore need to know how long the array is. Because there is no way in C to know how many elements are in an array that is a formal parameter to a function, you will have to tell it how long the array is. You could pass in the length of the array as another input parameter to the function, but for the sake of gaining experience with global variables, you will do it differently for this lab. Above all functions, define a constant, global variable called MAX_STRING_SIZE of an appropriate type and make it large enough to contain all strings you expect to enter for this program. (Too small, and some strings won't fit. Too large, and you waste memory.) Assume that the character arrays in your encodeStr() routine are at most this size. Write a main() routine to test your encodeStr() routine. You should declare two character arrays of size MAX_STRING_SIZE: one as an input to your routine and one as the output. Define a variable called shift and pass it to the encodeStr() routine along with the two strings. For your test, initialize the input string to whatever you want to encode. Then, output the input string and the output string, each surrounded by double quotes to mark the beginning and the end of the string. Test the following strings using several values of shift, including positive, negative and zero values: "Hello, World

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

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions

Question

How do religious subcultures affect consumption decisions?

Answered: 1 week ago

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago