Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

strxfrm() ใน C/C++

strxfrm() แปลง source string ให้เป็น current locale แล้ว copy ตัวอักษรแรก n ตัวไป destination ประกาศใน locale.h

ไวยากรณ์

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

destination: pointer ปลายทาง, source: string ต้นทาง, number: จำนวนตัวอักษรที่ copy

ตัวอย่าง

#include <stdio.h>
#include <string.h>

int main() {
    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

strxfrm() คืนค่าความยาวของ transformed string (ไม่รวม null terminator) copy แค่ 5 ตัวแรกไป d