我在妳的基礎上作了壹下修改,妳參考壹下,代碼如下:
#include<stdio.h>#include<string.h>
void?a(char?*p)
{
char?temp[100];
int?b=?strlen(p);
int?k=?0;
char?temp1[100];
inti=?0;
for(i=0;i<b;i++)
{
temp[i]=p[b-i-1];
}
temp[b]='\0';
puts(temp);
int?j=?0;
//要循環結束條件為:?j?<=?b
for(j=0;j<=b;j++)
{
//此處應為判斷,用?'==',還要考慮句尾的情況,要不最後壹個單詞打印不出來
if(temp[j]=='?'?||?temp[j]?==?'\0')
{
int?l=?0;
for(;k<j;k++)
{
temp1[k]=temp[j-l-1];
l++;
}
//在單詞之間添加空格
temp1[j]=?'?';
k++;
}
}
temp1[b]='\0';
puts(temp1);
}
int?main()
{
char?ch[100];
printf("zifushuan\n");
gets(ch);
a(ch);
return?0;
}
運行截圖:
希望這能夠幫助妳