Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C programming: 1. Write a function called recursively_reverse_string ( ) that ac

ID: 3688226 • Letter: C

Question

C programming: 1. Write a function called recursively_reverse_string( ) that accepts a pointer to a string as a parameter, and any other parameters you see fit, recursively reverses the string, and returns a pointer to the reversed string. For example, the reversed string of input “string” is “gnirts”. 2. Write a function called recursive_string_copy( ) which accepts a pointer to a source string and a pointer to a destination string as parameters, recursively copies from the source to destination (including the null character), and returns nothing. You may not use any functions from <string.h>. Hint: each recursive step requires that you pass in the address of the next character to copy from the source and the address of the next destination character location. C programming: 1. Write a function called recursively_reverse_string( ) that accepts a pointer to a string as a parameter, and any other parameters you see fit, recursively reverses the string, and returns a pointer to the reversed string. For example, the reversed string of input “string” is “gnirts”. 2. Write a function called recursive_string_copy( ) which accepts a pointer to a source string and a pointer to a destination string as parameters, recursively copies from the source to destination (including the null character), and returns nothing. You may not use any functions from <string.h>. Hint: each recursive step requires that you pass in the address of the next character to copy from the source and the address of the next destination character location. 1. Write a function called recursively_reverse_string( ) that accepts a pointer to a string as a parameter, and any other parameters you see fit, recursively reverses the string, and returns a pointer to the reversed string. For example, the reversed string of input “string” is “gnirts”. 2. Write a function called recursive_string_copy( ) which accepts a pointer to a source string and a pointer to a destination string as parameters, recursively copies from the source to destination (including the null character), and returns nothing. You may not use any functions from <string.h>. Hint: each recursive step requires that you pass in the address of the next character to copy from the source and the address of the next destination character location.

Explanation / Answer

Answer:

1.

# include <stdio.h>

/* recursively_reverse_string function that accepts a pointer to a string and print reverse of the passed string */


void recursively_reverse_string(char *passed_string)
{
if (*passed_string)
{
reverse(passed_string+1);
printf("%c", *passed_string);
}
}

int main()
{
char input[] = "string";
recursively_reverse_string(input);
return 0;
}

2.

#include<stdio.h>
void recursive_string_copy(char*,char*);
void main()
{
char*input_string="string";
char output_string[40];
recursive_string_copy(output_string,input_string);
printf(" %s",output_string);
getch();
}
void recursive_string_copy(char *destination,char *source)
{
while(*source!='')
*destination++=*source++;
*destination='';
return;
}