string reverse without new array

Posted by Codeguru on Stack Overflow See other posts from Stack Overflow or by Codeguru
Published on 2010-03-19T05:54:35Z Indexed on 2010/03/19 6:01 UTC
Read the original article Hit count: 122

Filed under:
|
|
|

hi can anybody tell me the error in this?

#include<stdio.h>

int main()
{
    char a[]="abcdefgh";
    int i=0;
    int n=strlen(a);
    char *first;
    char *second;
    char *c;
    *first=a[0];
    *second=a[7];
    for(i=0;i<=n/2;i++)
    {
            *c=*first;
            *first=*second;
            *second=*c;
            first++;
            second--;
    }

    for(i=0;i<=7;i++)
    {
            printf("%c",a[i]);
    }
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about string