"Interview frequently" C language: Input: "Student A Am I", output "I am a student, cannot use library function

Source: Internet
Author: User

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

#include <stdio.h>//#include  <assert.h>void my_reverse (char *left ,char *  right) { //assert (left);  //assert (right);    is null for handling pointer functions, guaranteeing a valid  while (left  < right)  {  char tmp =  *left;  //reverse   with intermediate variables  *left =  *right;  *right = tmp;  left ++;   Right --; }}int my_strlen (CHAR&NBSP;*STR)//Get the array length definition to find the function of string length { int count =  0; while (*str++)  {  count ++;  }  return count; // Returns the specified value of Count point int}void reverse (char arr[])   //char *arr{  char *pstart  = arr; char *pend = arr + my_strlen (arr)  -1; //Note array starting from 0  char *pcur = null; if ((arr == null)  | |   (arr[0]== '))  //empty array or array end, do not process  { &nbsP;return ;    } my_reverse (pstart,pend);   //inverse entire array  while (*arr)// Not NULL, for the case of '  {  pcur =arr;  //' array start address   while (*arr != '   && *arr != '   ')   //inside the word   {   arr++;  }   pend =arr - 1;  //back a   my_reverse (pcur, pend);     //the word   if (*arr ==  '   ') that encounters a space is followed by a word    {  //    arr++;   } }}int main () { char arr[] =  "Student  a am i ";    //idea: The string is reversed first, and then encountered in the space to reverse the word  reverse (arr);  printf ("%s\n ", ARR);  return 0; }

650) this.width=650; "title=" capture. PNG "src=" http://s3.51cto.com/wyfs02/M00/75/45/wKiom1Y0Pf-Cth4SAADIeoaWUZc883.jpg "alt=" Wkiom1y0pf-cth4saadieoawuzc883.jpg "/>

"Interview frequently" C language: Input: "Student A Am I", output "I am a student, cannot use library function

Related Article

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.