Question
// Problem 3: reverseOneString (15 points) // Reverse the string s by using pointer. // Use pointer p and 'temp' char to swap 1st char
// Problem 3: reverseOneString (15 points) // Reverse the string s by using pointer. // Use pointer p and 'temp' char to swap 1st char with last, then 2nd char with (last-1) and so on.. // Finally return pointer p which points to start of the reversed string. // You may declare and use more pointers if needed. // Hint: You might want to check if your logic works with even as well as odd length string. // You can write test code to print out the reversed string to check if your function works. (Don't include it in final submission) char* reverseOneString(char s[STRING_LENGTH]) { char temp; // not necessary to use this variable char *p = &s[0]; // pointer to start of string // enter code here
return p; }
// Problem 4: reverseStrings (5 points) // Reverse all the strings in 'strings[][]' // For each string in 'strings', use the reverseOneString() to reverse it. // You may declare and use more pointers if needed. void reverseStrings(char strings[NUM_STRINGS][STRING_LENGTH]) { char *ptr = &strings[0][0]; // enter code here
}
Step 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