Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Created October 12, 2015 14:42
Show Gist options
  • Save benaryorg/0990f100aa47ce81b308 to your computer and use it in GitHub Desktop.
Save benaryorg/0990f100aa47ce81b308 to your computer and use it in GitHub Desktop.
#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