Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Kindly need the answer in C Programming !!! Background: In C, a string is simply defined as an array of characters terminated by a special
Kindly need the answer in C Programming !!!
Background: In C, a string is simply defined as an array of characters terminated by a special symbol: 10'.lf we want to store a string "hello", we need to allocate an array of minimum size 6.We can create a pointer to S: char *ptrS S; Then if we apply pointer arithmetic and increment the pointer ptrS+t we can show that the pointer ptrS now points to the second item in the array (index 1). Refer to the figure below. How can we extract the letter 'e' using the pointer? (Answer: use *ptrS which is now equivalent to S[1]... Check!). ptrS Requirements: PART I: Storing a string. [ESTIMATED TIME 15 MINUTES] 1. Declare a char array called Buffer1 and initialize it to "this is the first buffer." using this method: {'t', 'h', 'i', 's', ' ', 'i', NO');2. 2. Declare a char array called Buffer2 and initialize it to "this is the second buffer." using this method: "this is the second buffer', 3. Declare a char array called Buffer3 of size 80 and leave it un-initialized 4. Use the scanf function to initialize Buffer3 from the keyboard. (note: use 965 for this) (prompt the user to type some string - if you encounter problems, document them and work out solutions for them.) 5. Now, use printf all three buffers and make note of the output. Document your declarations and all assumptions PART Il: Using a pointer to access the array. [ESTIMATED TIME 15 MINUTES 1. Declare a pointer variable named pBuffer and initialize it to point to Buffer3. (use char * pBuffer) 2. Now display the contents of Buffer3 (whose input was obtained from part-l above) using a while loop (or do/while). Your stop condition is of course when your pointer reaches the 10' symbol. PART IlIl: String Manipulation: Reverse. [ESTIMATED TIME 30 MINUTES] 1. OK, this is a little more challenging and you need to carefully prepare a thorough algorithm before you code this. 2. Write a function called Reverse that accepts as a parameter a char array (or char pointer) and returns a void. The function reverses the contents of the array (or string) being passed. Example: the string "Hello" will be reversed to "olleH". You have to be careful about the "1O' symbol to keep it at the end of the array and watch out for odd and even length strings. 3. Test your function and display the string (array) before and after it is reversed. 4. Repeat this function using recursion. Name your function RecursiveReverse. 5. IMPORTANT: The function does NOT print the string in reverse, it actually reverses it in memoryStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started