Menu

(Solved) : Write Function Called Reverse Accepts C String Argument Reverses Argument Place Meaning Cr Q43990424 . . .

Write a function called reverse that accepts a c-string as an argument and reverses that argument in place (meaning you shoul

In C, please.

Write a function called reverse that accepts a c-string as an argument and reverses that argument in place (meaning you should not create another array to store the result) returning the address of the first element of the c-string as a character pointer when you are finished. For example, if your c-string contains the string “Happy Birthday!” then after a call to the function your string would contain “!yadhtriB yppaH”. For this assignment you may not use the string.h library or any other library except stdio.h. You may assume the following main program which would print the string forward, backward, and then forward again twice: #include <stdio.h> char *reverse char *word); int main(int argc, char* argv []) char word [1] = “Happy Birthday!” ; printf(“%sn”, word); reverse word); printf(“%sn”, word); printf(“%sn”, reverse (word)); printf(“%sn”, word); return 0; } Place the code for your function in a file called reverse.c and submit only this file to me on blackboard. The file should contain the definition for your function reverse and nothing else. I will use my own header file and main program to test your code. Please keep in mind that this function should work for any valid C style string and the fact that the above program works for “Happy Birthday!” is just one example. You should try it with strings of even and odd lengths as well as very short strings. Show transcribed image text Write a function called reverse that accepts a c-string as an argument and reverses that argument in place (meaning you should not create another array to store the result) returning the address of the first element of the c-string as a character pointer when you are finished. For example, if your c-string contains the string “Happy Birthday!” then after a call to the function your string would contain “!yadhtriB yppaH”. For this assignment you may not use the string.h library or any other library except stdio.h. You may assume the following main program which would print the string forward, backward, and then forward again twice: #include char *reverse char *word); int main(int argc, char* argv []) char word [1] = “Happy Birthday!” ; printf(“%sn”, word); reverse word); printf(“%sn”, word); printf(“%sn”, reverse (word)); printf(“%sn”, word); return 0; } Place the code for your function in a file called reverse.c and submit only this file to me on blackboard. The file should contain the definition for your function reverse and nothing else. I will use my own header file and main program to test your code. Please keep in mind that this function should work for any valid C style string and the fact that the above program works for “Happy Birthday!” is just one example. You should try it with strings of even and odd lengths as well as very short strings.

Expert Answer


Answer to Write a function called reverse that accepts a c-string as an argument and reverses that argument in place (meaning you …

OR