A
ashok.anbalan
I tried using the string reversal routine that occurs in K & R 2nd
edition (Pg. 62) & the program core dumps.
#include <stdio.h>
#include <stdlib.h>
void reverse ( char s[] )
{
int c, i, j;
printf("\nInput string is %s",s);
for (i=0, j= strlen(s)-1;i<j;i++,j--)
{
c = s;
s = s[j];
s[j] = c;
}
printf("\nReversed string is %s",s);
}
int main()
{
reverse("abcd");
}
Apart from the two prints, this is an exact copy of the routine. I am
using gcc on Cygwin.
Can someone tell me whats going wrong?
Thanks,
Ashok
edition (Pg. 62) & the program core dumps.
#include <stdio.h>
#include <stdlib.h>
void reverse ( char s[] )
{
int c, i, j;
printf("\nInput string is %s",s);
for (i=0, j= strlen(s)-1;i<j;i++,j--)
{
c = s;
s = s[j];
s[j] = c;
}
printf("\nReversed string is %s",s);
}
int main()
{
reverse("abcd");
}
Apart from the two prints, this is an exact copy of the routine. I am
using gcc on Cygwin.
Can someone tell me whats going wrong?
Thanks,
Ashok