Created
January 21, 2016 02:28
-
-
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
This file contains 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
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