首页 > 其他分享 >将一句话的单词进行倒置,标点不倒置。比如I like beijing.经过函数后变为beijing like I

将一句话的单词进行倒置,标点不倒置。比如I like beijing.经过函数后变为beijing like I

时间:2022-12-15 16:04:48浏览次数:44  
标签:beijing arr right end like char start 倒置 left

#include<stdio.h>

#include<string.h>

#include<assert.h>


void reverse(char*left,char*right)

{

 while(left<right)

 {

   char tmp = 0;

tmp = *left;

*left = *right;

*right = tmp;

left++;

right--;

 

 }

 

}


int main()

{

char arr[100] = {0};

 

int len = strlen(arr);

char *start = arr;

reverse(arr,arr+len-1);

gets(arr);

while(*start)

{

 char*end = start;

 while(*end !=' '&& *end !='\0')

 {

 

    end++;

 }

 reverse(start,end-1);

 if(*end == ' ')

 start = end+1;

 else

  start = end;

}



printf("%s\n",arr);



return 0;

}

标签:beijing,arr,right,end,like,char,start,倒置,left
From: https://blog.51cto.com/u_13668714/5940185

相关文章