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
Advertisements Advertisements
 

 

 

DMCA.com