源程序:
#include < iostream >
#include < string >
using namespace std;
int strlen(char *str)
{
int len = 0;
while (str[len] != ' ')
{
len++;
}
return len;
}
void revers(char *b)
{
char c;
int j, len;
len = strlen(b);
j = len / 2 - 1;
while (j >= 0)
{
c = *(b + j);
*(b + j) = *(b + len - j - 1);
*(b + len - j - 1) = c;
j--;
}
b[len] = ' ';
}
void main()
{
cin.get();
char *s;
char str[10];
cout << "输入一个字符串:";
s = str;
cin.getline(s, 10);
//char str[]={"1234567890"};
cout << str << "----的长度:" << strlen(str) << endl;
cout << str << endl;//倒序前
revers(str);//
cout << str << endl;//倒序后
system("pause");
}
运行结果: