How to reverse a string using a recursive function, with
swapping?

Answer Posted / vignesh1988i

the corrected code is:::

#include<stdio.h>
#include<conio.h>
char a1[50]; //GLOABAL VAR.
void reverse(int);
void main()
{
int count=0;
printf("enter the string :");
scanf("%s",a1);
for(int i=0;a1[i]!='\0';i++)
count++;
reverse(count);
getch();
}

void reverse(int count1)
{
char temp;
static int i=0;
if(i!=count)
{
temp=a1[i];
a1[i]=a1[count1-1];
a1[count1-1]=temp;
i++;
reverse(--count1);
}
else
printf("\nthe reversed string is :%s",a1);
}

Is This Answer Correct ?    1 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon

5697


Why pointers are used in c?

755


What is maximum size of array in c?

773


What is a stream in c programming?

821


What tq means in chat?

836


Is it better to use a macro or a function?

893


What are the types of type specifiers?

802


Explain pointer. What are function pointers in C?

827


Explain how can I remove the trailing spaces from a string?

808


How can I prevent another program from modifying part of a file that I am modifying?

835


What is the collection of communication lines and routers called?

854


How can you tell whether two strings are the same?

1038


What are the 4 types of functions?

793


Multiply an Integer Number by 2 Without Using Multiplication Operator

544


How can I remove the trailing spaces from a string?

816