Comment

Craig Burnett
really?,
May 25, 2009 at 9:04 PM

Did you test your code before posting? It just switches the first and last char because there is no loop. Try this:

-------------------------
#include <stdio.h>
#include <string.h>

#define BUFSIZE 40

int reverse(char *s);

int main()
{
char s[BUFSIZE+1] = "Hello World!";

printf("\nThe string is: %s\n", s);
reverse(s);
printf("\nReversed string is: %s\n", s);
return 0;
}

int reverse(char *s)
{
int i, c, ln = strlen(s);

for (i = 0; i < ln/2; i++) {
c = s[ln-1-i];
s[ln-1-i] = s[i];
s[i] = c;
}
return 0;
}
----------------
View All Comments
Advertisement
Related Tutorial and Articles
C++

C Tutorials
 

Blog

Site map - C Tutorials
 

C Tutorials

C String Reverse
 

Programming Tutorials

C++Tutorials
 

CVS Questions

c++
 

Java Tips and Examples

String Reverse in Java
 

Development process Questions

reverse albhabet
 

Java Tips and Examples

String Reverse Using StringUtils
 

Mobile Applications Questions

objective c if string equals
 

Mobile Applications Questions

Parsing string in objective c
 

Java Code Examples

Java reverse words in a string using only loops
 

Mobile Applications Questions

copy string to string objective c
 

Java Beginners

c c++ - Java Beginners
 

Swing AWT

c c++ - Swing AWT
 

Ajax Questions

c#
 

CVS Questions

C++
 

Development process Questions

C++
 

Java Beginners

C# question
 

Development process Questions

c++
 

Ajax Questions

c#
 

Development process Questions

c++
 

Development process Questions

C++
 

Java Beginners

c++
 

Java Beginners

c++
 

Java Beginners

c++
 

Development process Questions

reverse alphabet
 

Development process Questions

C++
 

Development process Questions

c++
 

Development process Questions

c++
 

Design concepts & design patterns Questions

C++
 

Development process Questions

c++
 

Java Beginners

C++
 

Java Beginners

C#
 

Development process Questions

C++
 

Java Beginners

Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
 

Java Beginners

Out of bounce exception in the string reverse program - Java Beginners
 

Development process Questions

C#
 

UML Questions

c++
 

UML Questions

c++
 

Development process Questions

c++
 

Development process Questions

c++
 

Development process Questions

C++
 

Spring Framework Questions

c++
 

UML Questions

c++
 

UML Questions

c++
 

UML Questions

c++
 

UML Questions

C++
 

Development process Questions

c++
 

UML Questions

c++
 

Development process Questions

c++
 

Java Beginners

c++
 

Development process Questions

c programing
 

Development process Questions

c programing
 

Mobile Applications Questions

convert char to string objective c
 

Programming Tutorials

C++GraphicsTutorials
 

Java Beginners

programming c#
 

Java Beginners

string
 

Ajax Questions

c++ new, delete, string class
 

Design concepts & design patterns Questions

classes in c++
 

Java Beginners

reverse
 

General

Reverse String
 

Development process Questions

C,C++
 

Tutorials

NSString in objective c
 

Java Interview Questions

reverse string
 

Development process Questions

C,C++
 

Core Java

Reverse String Program in Java
 

Development process Questions

all c library functions
 

SQL Question

C program - SQL
 

Mobile Applications Questions

Select string from array in objective c
 

Java Interview Questions

about c and java
 

Java Beginners

turbo C Question 5.
 

Java Beginners

c program - Java Beginners
 

Mobile Applications Questions

match string to regular expression - Objective C
 

C Tutorials

C String to Int
 

C Tutorials

C String Substring
 

C Tutorials

C String Copy
 

Framework Questions

c postfix - Framework
 

IoC Questions

c program - IoC
 

Java Beginners

help with substring in c programing
 

C Tutorials

C String length
 

Development process Questions

c/c++ - Development process
 

Mobile Applications Questions

Why NSString Objective C
 

Framework Questions

C# Error - Framework
 

General

C Tutorials
 

Development process Questions

C Programming SubString Program
 

Java Beginners

variable declaration in c and c++
 

Development process Questions

c/c++ - Development process
 

HTML Questions

Visual studio C#
 

General

C Tutorials
 

Development process Questions

C++ program not running
 

Java Beginners

C# - Java Beginners
 

Development process Questions

C/C++ - Development process
 

Java Beginners

basic c/c++ questions
 

Java Beginners

basic c/c++ questions
 

Java Beginners

C/C++ QUESTIONS
 

Development process Questions

c/c++ - Development process
 

Development process Questions

c/c++ - Development process
 

Java Beginners

c c++ - Java Beginners
 

Java Beginners

c or c++ - Java Beginners
 

Hibernate Interview Questions

How ro convert char into string using recursive function in c#??
 

Advertisements Advertisements
 

 

 

DMCA.com