The contents of the character array are: "Student a Am I"; change the contents of the array to: "I am a student"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.