C function delimiates strings using a single character array I am a complete noob to C and I've shied away from using such a powerful language due to it's large learning curve and other complicated mechanisms. For my first minor project I plan to create a small HTTP client that requests for a webpage. Before I start, I need to create a function that can correctly parse a URL using the URI scheme. I devised this function to help me separate http from a host name like www.google.com by recognizing ://. Space and clock efficiency is are priorities of mine. I'm looking for any tips that would help someone who is new to C.

int delimiateString(const char *string, const char *delimiator) {
    const char *buffer;
    int x, len = strlen(delimiator);
    for (buffer = string; *buffer != '\0'; buffer++) {
        if (*delimiator == *buffer) {
            for (x = 1; x &lt;= len; x++) {
                if (*(delimiator+x) == *(buffer+x)) {
                    if (x+1 == len) {
                        return (buffer - string);
                    }
                } else {
                    break;
                }
            }
        }
    }
    return strlen(string);
}
Your function seems to do this:


Find the first occurrence of "delimiator" (delimiter?) in some string. For example find the first occurrence of :// in http://example.com.
If found, return the position where it was found
If not found, return the length of the input string


To find if a string is part of another string, you can use the strstr function.
This is equivalent to your code but simpler:

int delimiateString(const char *string, const char *delimiator) {
    char * found = strstr(string, delimiator);
    return found != NULL ? found - string : strlen(string);
}


For the record,
your original code can be simplified,
by eliminating an if around the inner for loop,
and rearranging the nested ifs at the deepest level:

for (buffer = string; *buffer != '\0'; buffer++) {
    for (x = 0; x &lt; len; x++) {
        if (*(delimiator+x) != *(buffer+x)) {
            break;
        }
        if (x+1 == len) {
            return buffer - string;
        }
    }
}