String finder function This function finds a certain string within a string. I feel like my function is too messy.

I'm new to C memory functions. Are there any shortcuts I can take to make this function shorter? Is this implementation effective?

bool strfound(char * find, char * name) {
    int j = 0;
    int size = strlen(name) + 1;
    char * buffer;
    buffer = (char*)malloc(size + 1);
    for (int i = 0; i &lt; size; i++) {
        std::cout &lt;&lt; buffer &lt;&lt; std::endl;
        if (i == 0 &amp;&amp; name[i] != ' ') {
            j++;
            buffer[j - 1] = name[0];
        }
        if (i != 0 &amp;&amp; name[i] != ' ') {
            buffer[j] = name[i];
            j++;
        }

        if (name[i] == ' ' || i == size - 1) {
            buffer[j] = '\0';
            if (strcmp(buffer, find) == 0) {
                std::cout &lt;&lt; "String is found: " &lt;&lt; buffer &lt;&lt; std::endl;
                buffer[j] = '\0';
                std::cout &lt;&lt; name &lt;&lt; std::endl;
                free(buffer);
                return true;
            }
            strcpy(buffer, ""); // or null from 0
            buffer = (char*)malloc(size + 1);
            j = 0;
        }
    }
    return false;
}


Output: https://gyazo.com/2fc0fe88958dfeb2f8cf20eff1f2d113
The answer to your primary question is yes, methods already exist in libraries that can do this. Reference this StackOverflow post.

Your method can then be simplified to what's shown below:

#include &lt;string&gt;

bool strfound(const std::string &amp;in, const std::string &amp;substr) {
    return in.find(substr) != std::string::npos;
}