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

Answer Posted / nitin

#include<stdio.h>
#include<conio.h>
#include<string.h>
char * reverse (char *);
void main()
{
char p[90],*k;

gets(p);
clrscr();
k=reverse(p);
puts(k);
getch();
}
char * reverse(char *p)
{
char *k="";


if (*p==NULL )
{
return("");
}
else
{
k=reverse(p+1);
}
k[strlen(k)]=*p ;
k[strlen(k)+1]=NULL;
return k;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is %d used in c?

559


Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer

3830


Who is the main contributor in designing the c language after dennis ritchie?

541


How to compare array with pointer in c?

610


can we change the default calling convention in c if yes than how.........?

2024






What does sizeof return c?

590


What are the types of data types and explain?

661


What is the difference between near, far and huge pointers?

624


State the difference between realloc and free.

619


What are lookup tables in c?

541


How do you construct an increment statement or decrement statement in C?

731


Explain is it valid to address one element beyond the end of an array?

724


What is the best way of making my program efficient?

559


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

1289


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

1623