C语言字符串反转代码分析及优化:将输入字符串的单词顺序反转
#include<stdio.h> #include<string.h>
char str[80]; char word[10][8]; int c=0; int j=0; int count=0;
int main() { fgets(str,sizeof(str),stdin); int len=strlen(str); for(int i=0;i<len;i++) { c=0; for(j=0;j<len;j++) { if(str[j]!=' ') { word[i][c]=str[j]; c++; } else { j++; count++; break; } } } for(int k =count-1;k>=0;k--) { printf("%s ",word[k]); } return 0; }
原文地址: https://www.cveoy.top/t/topic/p4lV 著作权归作者所有。请勿转载和采集!