Created
October 12, 2015 14:42
-
-
Save benaryorg/0990f100aa47ce81b308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdio.h> | |
#include <string.h> | |
size_t strchcount(const char *str,int ch) | |
{ | |
size_t count = 0; | |
const char *s = str-1; | |
while(s=strchr(s+1,ch)) | |
{ | |
count++; | |
} | |
return count; | |
} | |
int main(int argc,char **argv) | |
{ | |
assert(argc == 3); | |
printf("%zu\n",strchcount(argv[1],*argv[2])); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment