1234567891011121314151617181920212223242526272829
#include "stdafx.h" #include "conio.h" #include "stdio.h" #include <iostream> using namespace std; void reverse(char *str){ char *end = str; char tmp; if(str){ while(*end){ //find end of the string ++end; } --end; //set one char back, since last char is null while(str < end){ tmp = *str; *str++ = *end; *end-- = tmp; } } } void main(){ char *myChar = "abcdefg"; reverse(myChar); cout << myChar << endl; _getch(); }