#include <stdio.h>
#include<stdlib.h>
#include <string.h>
int main()
{
int cnt=0;
int j=0;
int k=0;
char array[200],t[40],ch,word[40][40];
while(scanf("%c",&ch))
{
if(ch=='?'||ch=='!'||ch=='.')
break;
array[cnt++]=ch;
}
array[cnt]=0;
//printf("%s\n",array);
for(int i=0;array[i]!=0;i++)
{
if(array[i]!=' ')
t[j++]=array[i];
else
{
t[j]=0;
if(j!=0){
strcpy(word[k++],t);
j=0;
}
}
}
t[j]=0;
if(j!=0){
strcpy(word[k++],t);
j=0;}
//printf("Enter a sentence: ");
//printf("Reversal of sentence: ");
for(int i=k-1;i>0;i--)
{
printf("%s ",word[i]);
}
printf("%s%c",word[0],ch);
}
效果:
输入:how are you?
输出:you are how?