Last active
August 29, 2015 14:02
-
-
Save brendanashworth/956405a90345f3ce477c to your computer and use it in GitHub Desktop.
Count occurrences of a string inside a string (C)
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 str_count(char *string, char *delim) { | |
int count = 0; | |
int i; | |
for (i = 0; i < strlen(string); i++) { | |
if (strncmp(&string[i], delim, strlen(string))) { | |
count++; | |
} | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment