1)IN C Write a function called recursively_reverse_string() that accepts a point
ID: 3689495 • Letter: 1
Question
1)IN C 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)IN C Write a function 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 . 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
#include<stdio.h>
#include<conio.h>
void strev(char *str1, char *str2);
void main()
{
char *str1, *str2;
clrscr();
printf(" ENTER A STRING...: ");
gets(str1);
strev(str1,str2);
printf(" THE REVERSED STRING IS...: ");
puts(str2);
getch();
}
void strev(char *str1, char *str2)
{
int i = 0, len = 0, r = 0;
while(*(str1+len)!='')
len++;
for(i=len-1; i>=0; i--)
{
*(str2+r) = *(str1+i);
r++;
}
*(str2+r) = '';
}
----------------------------------------------------------
#include<stdio.h>
void copystr(char*,char*);
void main()
{
char*str1="I am Avinash";
char str2[30];
clrscr();
copystr(str2,str1);
printf(" %s",str2);
getch();
}
void copystr(char *dest,char *src)
{
while(*src!='')
*dest++=*src++;
*dest='';
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.