#include <stdio.h> #include <assert.h>int length (const char *str) { int len=0; assert (str); while (*STR) { len++; str++; } return len;} Void reverse_str (char *start,char *end) { while (start<end) { char tmp=*start ; *start=*end; *end=tmp; start++; end--; }} Char *reverse(CHAR&NBSP;*STR) { int n=length (str); char *ret=str; //first saves the starting position in the RET char *start=str; char *end=str+n-1; reverse_str (Start,end); while (*STR) { start=str; while (*str!= ' ' ) & & (*str!= ')) { str++; } end=str-1; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;REVERSE_STR ( Start,end); iF (*str== ' ' ) { str++; } } return ret;} Int main () { char str[]= "student a am i " ; printf ( "%s\n ", reverse (str)); system ( "pause"); return 0;}
This article from "Thanksgiving" blog, reproduced please contact the author!
The contents of a character array are: "Student a Am I", please change the contents of the array to "I am a student".