C语言字符串逆序输出:将“hello world”改为“world hello”
#include<stdio.h> #include<string.h>
char str[80]; char word[10][8]; int c=0; int j=0; int main() { fgets(str,sizeof(str),stdin); int len=strlen(str); for(int i=7;i>=0;i--) { c=0; for(;j<len;j++) { if(str[j]!=' ') { word[i][c]=str[j]; c++; } else {
j++;
break;
}
}
}
for(int i =0;i<8;i++)
{
printf('%s',word[i]);
printf(' ');
}
return 0;
}
输入:
hello world
输出:
world hello
原文地址: https://www.cveoy.top/t/topic/p4lu 著作权归作者所有。请勿转载和采集!