Problem Description: The contents of a character array are: "Student a Am I", please change the contents of the array to "I am a student".
Code implementation:
#include <stdio.h>void swap (char *a,char *b) { *a = *a + *b; *b = *a - *b; *a = *a - *b;} Void reverse (char *arr,int left,int right)//student a am i{ while (left < right) { swap (&arr[left],&arr[right]);//arr[0] left++; right--; }}int main () { int left = 0; int right = 0; char arr[]= "Student a am i"; reverse (arr,0,sizeof (arr)/sizeof (arr[0])-2 );//student\0 while (arr[right] != ') { while (arr[right] != ') &&arr[right] != ' ') { right++; } right--; reverse (Arr,left, right); left = right+2; right = left; } printf ("%s\n", arr); return 0;}
The result is:
650) this.width=650; "title=" Wkiol1zhvtrtuelsaabryoltio4226.png "src=" http://s2.51cto.com/wyfs02/M00/76/00/ Wkiol1zhwmnc3mx4aabcxi2xhby281.png "alt=" Wkiol1zhwmnc3mx4aabcxi2xhby281.png "/>
This article is from the "Pzd Chuan Feng" blog, please make sure to keep this source http://xujiafan.blog.51cto.com/10778767/1712820
C-language Inverse string array