Flipping each word in a string
//The flip of each word in the string. CPP: The entry point that defines the console application. //#include "stdafx.h"#include <iostream>#include <windows.h>using namespace STD;voidREVSTR (Char* src) {Char*START=SRC,*END=SRC,*PTR=SRC; while(*ptr++!=' + ') {if(*ptr=="'|| *ptr==' + ') {end=ptr-1; while(start<end) swap (*start++,*end--);//Reverse the letter of the wordstart=end=ptr+1;//Point to the beginning of the next word}} start=src,end=ptr-2;//start points to the beginning of the string, end points to the end while(Start<end) {swap (*start++,*end--);//Reverse the entire string}}intMain () {Charsrc[]="I am from Chengdu";cout<<src<<"\ n"; REVSTR (SRC);cout<<src<<"\ n"; System"Pause");return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Flipping each word in a string