Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C reversing a string

Name: Anonymous 2012-10-29 12:00

Why does "printf("%c, reverse")" just put out "aggiN", but ("%s, reverse") outside of the loop put out "aggiNNigga" when it should do the same?

int main(int argc , char* argv [ ] ) {

    int i=0;
    int c;
    int a=0;
    char string[]="Nigga";
    char reverse[20];

    i=sizeof(string);
    printf("%d\n", (i-1));

        for(c=i-2;c>=0;c--)
        {
            reverse[a]=string[c];
                        printf("%c", reverse[a]);
                        a++;

        }
    printf("\n%s", reverse);
    return 0;
}

Name: Anonymous 2012-10-30 12:42

Now in D


string reverse(string str)
{
    import std.range;

    return retro(str);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List