StrSwapCharAt

Table of Contents

StrSwapCharAt

Description

Swap chars at given indices.

Parameters

NameDirectionDescription
strin,outStr to swap chars in.
idx1inIndex/Position of first char.
idx1inIndex/Position of second char.

Success

return

Failure

Does not return

Usage example (Cross-references)

    // Test StrSwapCharAt function
    bool test_str_swap_char_at(void) {
    printf("Testing StrSwapCharAt\n");
    
    Str s = StrInitFromZstr("Hello");
    
    // Swap 'H' and 'o'
    StrSwapCharAt(&s, 0, 4);
    
    // Check that the characters were swapped
    
    // Swap 'e' and 'l'
    StrSwapCharAt(&s, 1, 2);
    
    // Check that the characters were swapped

Share :