Write a program to reverse the strings stored in the following array of pointers to strings:
char *s[ ] = {
"To err is human...",
"But to really mess things up...",
"One needs to know C!!"
};
Hint: write a function
xstrrev ( string )
which should reverse the contents of one string. Call this function for reversing each string stored ins
.
Why am I not getting correct output with this code?
#include "stdafx.h"
#include "conio.h"
#include "stdio.h"
#include "string.h"
using namespace System;
void xstrrev (char str[])
{
int i,l;
char temp;
l=strlen(str);
for (i=0;i<(l/2);++i)
{
temp=*(str+i);
*(str+i)=*(str+i+l-1);
*(str+i+l-1)=temp;
}
}
void main ()
{
char *s[] = {
"To err is human...",
"But to really mess things up...",
"One needs to know C!!"
};
xstrrev(s[0]);
xstrrev(s[1]);
xstrrev(s[2]);
puts(s[0]);
puts(s[1]);
puts(s[2]);
getch();
}