Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THE LANGUAGE IS C, THE LAST 2 PICS ARE THE .c FILE, THE CODE SHOULD ALSO BE IN POINTER NOTATION This week we're covering pointers,

image text in transcribedimage text in transcribedimage text in transcribed THE LANGUAGE IS C, THE LAST 2 PICS ARE THE .c FILE, THE CODE SHOULD ALSO BE IN POINTER NOTATION

This week we're covering pointers, and you should by now have completed all the readings on pointers, so you can start thinking about how best to approach this exercise. The goal of this exercise is to: - Help you practice using pointers to access information that is not declared inside some function - Help you practice using pointers to change information that lives outside a function - Help you better understand the relationship between strings, arrays, and pointers (you solved a string problem for Ex.2 using arrays, think about how you could have done it with pointers instead) Your task: Implement one function: wordSwapper() - Takes two pointers, one for an input string, and one for a different (we don't know what's in it, possibly junk) string. The function updates the second (destination) string so that it contains the same words as the input string, but in reverse order (the last word appears first, and vice versa). See the starter code below for details! fun with pointers2020.c a The starter code describes what you have to complete. Compiling the code For this exercise, we will start practicing compiling with more strict settings, we will add two flags to the compiler call. -Wall : Uses more strict checking for warnings, and reports anything it finds -Werror :Makes the compiler treat the warnings as if they were errors so you have to fix them in order to obtain an executable program. Please note - this flag may not be available or work properly on Mac, so it's up to you to treat warnings as errors and make sure you clear all of them. We will compile your exercise code, as well as ANY CODE YOU SUBMIT FROM NOW ON, using these flags, your code won't compile on our test machine if warnings have not been cleared. The compiler call will look like: gcc -Wall -Werror fun_with_pointers2020_studentNo.c Expected output - Once you completed the exercise, the output of your program should look like this: ...\a.exe The original string is: silence .is a looking bird:the turning; edge, of life. e. e. cummings Destination string after swapping: cummings e. e. life. of edge, turning; bird:the looking a .is silence Do not change any of the printf() statements in the program! They are already formatted to produce the output above if you completed the required functions properly. #include #include #define MAX_STR_LEN 1024 // DO NOT USE the string library for this exercise void wordSwapper (char *source, char *destination) { // This function takes a pointer to a 'source' string (an array // of chars, with maximum size MAX_STR_LEN), and // makes a new string inside the 'destination' string // (which is also passed as a pointer) so that the order // of the words in the destination string is the reverse // of the order in the source string. // // e.g. if: // The 'surce' string contains "Hello I Am A String!" // // then the destination string will contain // // 'String! A Am I Hello" // (notice that we add a space between each word in the // destination string // // The only character to be used in separating words is // a blank space, so any other characters are considered // part of a word, for example "Hello, I; Am! A. *String*" // will becoe "*String* A. Am! I; Hello," // these are *added*, not *copied*) // You *MUST* use pointers and pointer addressing to complete // this exercise (that is, no array notation with brackets []), // and you can not assume the 'destination' string is empty, // it could (and likely does) contain junk. // // If you decide to write helper functions, make sure they // are placed *above* this function's code. // TO DO: Complete this function #ifndef TESTING int main() #ifndef int main() { char source[MAX_STR_LEN]="silence .is a looking bird:the turning; edge, of life. e. e. cummings"; char destination[MAX_STR_LEN]="I am a destination string and I contain lots of junk 1234517265716572@qsajdkuhasdgsahiehwjauhiuiuhdsj!"; _TESTING printf("The original string is: %s ", source); // Call word swapper with the address of the first character in 'source' and the first character in 'destination' wordSwapper (&source[0], &destination[0]); // You could also call wordSwapper like this: wordSwapper (source, destination) since, as we will have seen in // lecture this week, the array's name can be used to pass into a function the address of the first entry // in the array. printf("Destination string after swapping: %s ", destination); } #endif

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

Analyse the various techniques of training and learning.

Answered: 1 week ago