Skip to content

Instantly share code, notes, and snippets.

@jkwill87
Created January 21, 2016 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkwill87/723341e2c43ff730a0b4 to your computer and use it in GitHub Desktop.
Save jkwill87/723341e2c43ff730a0b4 to your computer and use it in GitHub Desktop.
A simple C function which returns the instance count of a character within a string
int strcnt(char s[], int c) {
char *pos;
int i = 0;
int count = 0;
do {
pos = s + i++;
if (*pos == c) count++;
} while (*pos);
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment