C語言 字串翻轉(以空格為界限,只翻轉單詞位置)

2021-09-29 13:18:02 字數 776 閱讀 3081

字串翻轉,以空格為界限,只翻轉單詞位置。可以經過以下兩個步來實現:

將字串整體先翻轉一遍student a am i -> i ma a tneduts

再以空格為界限翻轉每個單詞 i ma a tneduts -> i am a student

**如下:

#define _crt_secure_no_warnings

#include

#include

#include

//翻轉字串

void

reverstr

(char

*start,

char

*end)

}//尋找邊界' '並翻轉

void

reversecharacters

(char

*str)

}int

main

(void);

char

*end =

null

;gets

(str)

; end = str +

strlen

(str)

;reversecharacters

(str, end)

;printf

("%s\n"

, str)

;printf

("\n");

system

("pause");

return0;

}

字串以空格翻轉

將以空格為分隔符分隔的字串逆序列印,但單詞不逆序。例如 hello world welcome to china 的列印結果為 china to welcome world hello include include print string str partially,from start to ...

去除字串中的空格,並將字串翻轉

前幾天參加校招,遇到乙個問題,現做分享。題意大致如下 將string world hello world 去除所有的空格,並將字元翻轉輸出 答 string b world.replace 去除空格 string c newstringbuffer b reverse tostring 利用stri...

C語言遞迴實現字串翻轉

一,c語言遞迴實現字串逆轉 簡單的實現 abc 的逆轉 函式原型 void reverse char value,char result char value為待逆序字串 char result為存放的逆序結果 1,首先判斷是否value是否為空和value是否是字串結尾條件 條件不滿足則retur...