vendredi 3 avril 2015

Please help me to check this code for string reverse in C

I'm writing this code to reverse the string, but somehow the last printf() seems can not print out the update string. I want to know why.



#include <stdio.h>

int main() {
char x[] = "abcdefghijklmn";
int j = sizeof(x);
int i = 0;
char t = 'a';
printf("%s,%i\n", x, j / 2);

for (; i < j / 2; i++) {
t = x[i];
x[i] = x[j - i - 1];
x[j - i - 1] = t;
printf("%c,%i,%i\n", x[i], i, j - i - 1);
}

printf("%s\n", x);

return 0;
}

Aucun commentaire:

Enregistrer un commentaire