_       _ _ _    _ _ 
| |     (_|_) |  (_) |
| | ___  _ _| | ___| |
| |/ _ \| | | |/ / | |
| | (_) | | |   <| | |
|_|\___/| |_|_|\_\_|_|
       _/ |           
      |__/           
    purveyors of fine, internet-related kipple since 1985.
    

. » p » lpn » 0 » index.txt
[10-MAR-2014 23:28]
A simple piece of coding inspired by this post on Reddit. Basically, a straight-forward substring test:
int
issubstring_p(const char *str, const char *sub){
    int str_idx = 0, sub_idx = 0, str_len = strlen(str), sub_len = strlen(sub);
    while(str_idx < str_len){
        if(str[str_idx] == sub[sub_idx]){
            sub_idx++;
        } else {
            sub_idx == 0;
        }
        if(sub_idx == sub_len){
            return 1;
        }
        str_idx++;
    }
    return 0;
}


The full code has some tests and the like. Of course, having written this, now I'm curious to see what it looks like hacked up in Digamma...
Home | About | Blag | Lojikil's Programmer Notebook | Projects | Twitter | Github | BitBucket