How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / prakash
Another version that actually reverses the string...
#include <stdio.h>
char *reverse(char *sstr, char *str, char c)
{
if (*str == '\0')
return sstr;
sstr = reverse(sstr, str+1, *(str+1));
*sstr = c;
return (sstr+1);
}
int main()
{
char str[100];
printf("Enter the string: ");
scanf("%s", str);
reverse(str, str, *(str + 0));
printf("Reversed string: %s\n", str);
return 1;
}
| Is This Answer Correct ? | 25 Yes | 11 No |
Post New Answer View All Answers
Can the “if” function be used in comparing strings?
What is the use of gets and puts?
Explain how can you determine the size of an allocated portion of memory?
What’s the special use of UNIONS?
Suppose we have a table name EMP as below. We want to perform a operation in which, I want to change name ‘SMITH’ from as ‘SMITH JAIN’. Also I want to change the name of the column from ENAME to E_NAME. EMPNO ENAME JOB MGR HIREDATE SAL 7369 SMITH Coder 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 7521 WARD SALESMAN 7698 22-FEB-81 1250
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
What is sizeof c?
Write a program to print "hello world" without using a semicolon?
what is bit rate & baud rate? plz give wave forms
Write a program to find the biggest number of three numbers in c?
Define Array of pointers.
Do pointers store the address of value or the actual value of a variable?
Should I learn c before c++?
What is volatile variable in c?
What’s a signal? Explain what do I use signals for?