Skip to content

StrFindCstr

StrFindCstr

Description

Find a fixed-length substring in a Str object.

Parameters

Name Direction Description
str in Str object to find str into.
key in Substring to look for.
key_len in Length of the substring to look for.

Success

char* providing position of found string. Pointer is inside str.

Failure

NULL

Usage example (Cross-references)

Usage examples (Cross-references)
                    char *cstr = generate_cstring(data, offset, size, 10);
                    if (cstr) {
                        char *found = StrFindCstr(str, cstr, strlen(cstr));
                        (void)found; // Suppress unused variable warning
                        free(cstr);
    // Test string find functions
    bool test_str_find(void) {
        WriteFmt("Testing StrFindStr, StrFindZstr, and StrFindCstr\n");
    
        Str haystack = StrInitFromZstr("Hello World");
    
        // Test StrFindCstr
        const char *found5 = StrFindCstr(&haystack, "Wor", 3);
        result             = result && (found5 != NULL && ZstrCompareN(found5, "World", 3) == 0);
Last updated on