标签:换顺序不换单词
将student a am I转换为 I am a student
#include <stdio.h> #include <string.h> void reverse( char *start,char *end ) { char* left = start; char* right = end; char temp; while( left < right ) { temp = *left; *left = *right; *right = temp; left++; right--; } } void check( char *p ) { while( *p != ‘\0‘) { char *pst = p; while( *p != ‘\0‘ && *p != ‘ ‘ ) { p++; } reverse( pst,p-1 ); if(*p!=‘\0‘) p++; } } int main() { char p[30] = "student a am i"; int len = strlen(p); printf("翻转后的字符串是:"); reverse(p,p+len-1); check(p); printf("%s\n",p); return 0; }
本文出自 “小止” 博客,请务必保留此出处http://10541556.blog.51cto.com/10531556/1679289
将student a am I转换为 I am a student(利用空格处理单词)
标签:换顺序不换单词
原文地址:http://10541556.blog.51cto.com/10531556/1679289