strxfrm() 在 C/C++ 中


strxfrm() 函式將源字串轉換為當前語言環境,並複製轉換字串的前幾個字元到目標中。在 C 語言中,它在“locale.h”標頭檔案中宣告。

以下是 strxfrm() 在 C 語言中的語法,

size_t strxfrm(char *destination, const char *source, size_t number)

其中,

destination − 目標指標,用於複製字元。

source − 要轉換的字串。

number − 要複製的字元數。

以下是 strxfrm() 在 C 語言中的示例,

示例

#include <stdio.h>
#include <string.h>
int main () has {
   char s[10] = "HelloWorld";
   char d[10];
   int n;
   n = strxfrm(d, s, 5);
   printf("Length of string : %d", n);
   return(0);
}

輸出

Length of string : 10

在上述程式中,聲明瞭兩個字元型別陣列。一個是目標,另一個是源(已轉換字元集從該源複製到目標)。它將只複製 “n” 個字元。

char s[10] = "HelloWorld";
char d[10];
int n;
n = strxfrm(d, s, 5);

更新於: 2020-6-26

253 次瀏覽

開啟你的 職業生涯

透過完成本課程獲得證書

開始
廣告