1.写一个函数将"tom is cat" 倒序打印出来,即 "cat is tom"。
#include "stdafx.h"
#include <iostream>
using namespace std;
//反字符串
#define SPACE ' ' //或者使用const char SPACE = ' ';
int main()
{
char* str = "Tom is cat fgfgfgfg juytf"; // 字符串
char* first= str+strlen(str)-1;
char* second = first + 1; // 开始时 俩都指向字符串结尾处
while(str != first--) //指针从结尾处开始循环递减到 字符串为空的
{
if(SPACE == *first) //第一个单词
{
for (int i = 1; first + i != second; ++i)
{
cout << *(first + i);
}
cout << " ";
second = first;
}
if (str == first)
{
for (int i = 0; first + i != second; ++i)
{
cout << *(first + i);