當前位置:編程學習大全網 - 編程軟體 - C語言把單詞順序倒置 比如see you later 編程later you see 我這個怎麽不行

C語言把單詞順序倒置 比如see you later 編程later you see 我這個怎麽不行

我在妳的基礎上作了壹下修改,妳參考壹下,代碼如下:

#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;

}

運行截圖:

希望這能夠幫助妳

  • 上一篇:從6名教師中選4名開發abcd四門課程
  • 下一篇:江蘇省中小學生建模大賽有哪些項目
  • copyright 2024編程學習大全網