samedi 27 juin 2015

Reverse a C-style string

Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.) Nothing is printed out.Why?

`void ReverseString(char *p){
    int length = strlen(p);
    for (int i = 0, j = length; i < j; i++, j--){
        swap(p[i], p[j]);
    }

}


int main()
{
    char a[] = "12345";
    ReverseString(a);
    cout << a;
    system("pause");
    return 0;
}`

Aucun commentaire:

Enregistrer un commentaire