How to find the number of occurrences of substring in a string?

I wrote this C code that can find the number of occurrences of a substring in a string. The problem is it overlaps meaning if I search for the letters pp in a string that has ppp the answer will be 2 occurrences instead of 1. I need help stopping this overlapping.

char* fullString = arguments[1];
    char* subString = arguments[2];
    int fullLength=strlen(fullString);
    int subLength=strlen(subString);
    int result = 0;

    for(int i=0;i<fullLength;i++){
        int check;
            if (fullString[i+check]!=subString[check])

    return result;

Read more here:

Content Attribution

This content was originally published by Ammar Montaser at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: