user-0 提问: 谁能帮我看一下这段代码到底哪有问题，输出结果本应是倒序打印字符串

回复:
user: user-1
content: #include <stdio.h> #include <string.h> #include <assert.h>  void revp (const char * c) {     assert (c != NULL);     int n = strlen (c);     while (n --) printf ("%c", c [n]); }

user: user-2
content: #include<iostream> #include<algorithm> #include<string> using namespace std; class mystring { 	private: 		string str; 	public: 		mystring(string s):str(s){} 		void myreverse(); 		void print_string(); }; void mystring::myreverse() { 	reverse(str.begin(),str.end()); } void mystring::print_string() { 	cout << str << endl; }  int main() { 	string a; 	cin >> a; 	mystring obj(a); 	obj.myreverse(); 	obj.print_string(); 	return 0; }

user: user-2
content: // reversing list #include <iostream> #include <list>  int main () {   std::list<int> mylist;    for (int i=1; i<10; ++i) mylist.push_back(i);    mylist.reverse();    std::cout << "mylist contains:";   for (std::list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it)     std::cout << ' ' << *it;    std::cout << '\n';    return 0; }

user: user-3
content: for(;(*ch) != '\0';)         printf("%c",*ch); 这个循环要么死循环，要么一次都不会执行

user: user-4
content: "asdasdasd"是在常量内存区分配的，你却在*ch2 = *cp试图修改该内存，要崩溃，修改为char  ch[] = "asdasdasd";至于其他问题，楼主再慢慢调试额

user: user-0
content: 引用 1 楼 zgxyz2010 的回复:"asdasdasd"是在常量内存区分配的，你却在*ch2 = *cp试图修改该内存，要崩溃，修改为char  ch[] = "asdasdasd";至于其他问题，楼主再慢慢调试额好吧，谢谢，这个的确不知道

user: user-5
content: /**  * @file    strrev.c  * @brief     */  #include <stdio.h> #include <string.h>  char * strrev(char *s) {     char  c;     char *b, *e;      for (e = s; *e != '\0'; e++)         ;     for (b = s, e--; b < e; b++, e--) {          c = *b;         *b = *e;         *e =  c;     }     return s; }  int main(void) {     char s[] = "0123456789ABCDEF";      printf("[%s]\n", strrev(s));     printf("[%s]\n", strrev(s));      s[15] = '\0';     printf("[%s]\n", strrev(s));     printf("[%s]\n", strrev(s));      s[14] = '\0';     printf("[%s]\n", strrev(s));     printf("[%s]\n", strrev(s));      s[10] = '\0';     printf("[%s]\n", strrev(s));     printf("[%s]\n", strrev(s));      s[9] = '\0';     printf("[%s]\n", strrev(s));     printf("[%s]\n", strrev(s));      s[1] = '\0';     printf("[%s]\n", strrev(s));     printf("[%s]\n", strrev(s));      s[0] = '\0';     printf("[%s]\n", strrev(s));     printf("[%s]\n", strrev(s));      return 0; }  /* output: [FEDCBA9876543210] [0123456789ABCDEF] [EDCBA9876543210] [0123456789ABCDE] [DCBA9876543210] [0123456789ABCD] [9876543210] [0123456789] [876543210] [012345678] [0] [0] [] [] */

user: user-5
content: #include<stdio.h> #include<string.h> int main(void) {      char   ch[] = "asdasdasd";      char * ch2;      char * cp;      int a,b;      char temp;       a = 1;      cp = ch;      ch2 = ch;      while(*(++cp) != '\0')         a++;      cp--;       for(b = 0;b <(a/2);b++)      {         temp = *ch2;         *ch2 = *cp;         *cp = temp;         ch2++;         cp--;      }      for(ch2 = ch; (*ch2) != '\0'; ch2++)         printf("%c",*ch2);              return 0;   }

user: user-6
content: #include <stdio.h> #include <string.h>   int main() { 	char tmp; 	char ch[] = "abcdefg"; 	int len = sizeof(ch)/sizeof(char); 	int i = 0, j = len - 2;//长度包括最后的'\0',所以最后的字符下标为len-2 	while (i < j) 	{ 		if (ch[i] != ch[j]) 		{ 			tmp = ch[i]; 			ch[i] = ch[j]; 			ch[j] = tmp;			 		} 		++i; 		--j; 	} 	printf("%s\n", ch); 	return 0; }