Skip to content

Instantly share code, notes, and snippets.

@brendanashworth
Last active August 29, 2015 14:02
Show Gist options
  • Save brendanashworth/956405a90345f3ce477c to your computer and use it in GitHub Desktop.
Save brendanashworth/956405a90345f3ce477c to your computer and use it in GitHub Desktop.
Count occurrences of a string inside a string (C)
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