The contents of a character array are : "Student A Am I", Please change the contents of the array to "I am a student".
Requirements: Library functions cannot be used. Only a limited space can be opened (the number of spaces is independent of the length of the string).
The code is as follows:
#include <stdio.h> #include <stdlib.h> #include <assert.h>void reverse_str (Char *left, char *right) {assert (left), assert (right);while (left < right) {char tmp = *left;*left = *right;*right = tmp;left++;right--;}} Int my_strlen (CONST&NBSP;CHAR&NBSP;*&NBSP;STR) {int count = 0;while (*str++) {count++;} Return count;} Void reverse (char arr[])//(CAHR&NBSP;*STR) {char *pstart = arr;char *pend = arr + my_strlen (arr) -1;char *pcur = null;if (Arr == NULL) || (arr[0] == ')) {return;} Reverse_str (pstart, pend);//reverse the entire character array while (*arr) {pcur = arr;while (*arr != ' && *arr != ' ') {arr++;} Pend = arr - 1;reverse_str (pcur, pend);if (*arr == ' ') arr++;}} Int main (){char arr[] = "Student a am i";//i ma a tneduts//i am a studentreverse (arr);p rintf ("%s\n", arr); System ("pause"); return 0;}
This article is from the "Materfer" blog, make sure to keep this source http://10741357.blog.51cto.com/10731357/1708644
The contents of the character array are: "Student a Am I"; change the contents of the array to: "I am a student"