Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
C String Reverse 
 

In this section, you will study how to reverse a string. You can see in the given example, a recursive function reverse(int i) is created.

 

C String Reverse

                         

In this section, you will study how to reverse a string. You can see in the given example, a recursive function reverse(int i) is created. Inside the method, we are calculating the length of a specified string using a library function strlen(). Then string st[i] and st[strlen(st)-i-1] are swapped as: c= st[i];  
st[i]=st[strlen(st)-i-1]; 
st[strlen(st)-i-1]=c;

Statements shown above will reverse the string.

Here is the code:

 

StringReverse.C

#include <stdio.h>
#include <conio.h>
#include <string.h>
int reverse(int i);
char st[]="Hello World";
void main() {
  printf("\nThe string is: %s", st);
  reverse(0);
  printf("\nReversed string is: %s", st);
  getch();
}
int reverse(int i) {
  if (i<(strlen(st)/2)) {
    char c;
    c= st[i];
    st[i]=st[strlen(st)-i-1];
    st[strlen(st)-i-1]=c;
  }
  return 0;
}

Output will be displayed as:

STRING~1.EXE

Download Source Code:

                         

» View all related tutorials
Related Tags: c ide function language fun io pointer vi int id address define poi unc add to point attach feature base

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

not used pointer.
i have input string: vishad
output display alphabetical revese
output need:vsihda

Posted by vishad on Thursday, 04.9.09 @ 08:32am | #86662

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.