将一句话里的单词倒置,句号不倒置

前端之家收集整理的这篇文章主要介绍了将一句话里的单词倒置,句号不倒置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/* * welcome to EMC company. Output:comany EMC to welcome. */ #include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ char str[] = "welcome to EMC company."; char temp; int begin,end; int j = strlen(str) - 2,i = 0; while(j > i){ temp = str[i]; str[i] = str[j]; str[j] = temp; j--; i++; } printf("%s\n",str); char endChar = str[0]; i = 0; while(str[i]){ if(str[i] != ' '){ begin = i; while(str[i]&&str[i]!=' '&&str[i]!='.') i++; //i = i-1; end = i-1; } while(end > begin){ temp = str[begin]; str[begin] = str[end]; str[end] = temp; end --; begin ++; } i++; } //str[i] = endChar; printf("%s\n",str); return 0; } 原文链接:https://www.f2er.com/javaschema/286317.html

猜你在找的设计模式相关文章