#include<stdio.h>
#include<string.h>
int main()
{
char a[85], b[50][85];
int len, count, i=0, j=0;
gets(a); //字符串中间有空格,用gets来接收输入
len=strlen(a);
for(count=0; count<len; count++) { //将字符串分类存储于二维数组中
if (a[count]!=' ') {
b[i][j]=a[count];
j++;
}else {
b[i][j]='\0'; //遇到空格时当前字符串末尾加'\0',并进行换行
i++;
j=0;
}
}
b[i][j]='\0'; //一开始漏掉了这句,因为a数组最后一个字符不是空格
for (count=i; count>0; count--) printf("%s ", b[count]); //逆序输出
printf("%s", b[0]);
}
1、字符串中间有空格,用gets来接收输入
2、将含有空格的一维字符串,分类存储于二维字符数组中
3、一开始漏掉了最后一行末尾的'\0'