All pastes #614130 Raw Edit

Mine

public text v1 · immutable
·published 2007-07-11 11:32 UTC
rendered paste body
#include <stdio.h> // Some standard functions in here
#include <string.h> // StrCMP
/* SUBSTR_COUNT
 * @ Method input: [WORD TO SEARCH FOR] [SENTECE]
 * @ Method return: INT, how much word apperas in sentece
 */
int count_words(char *, char *); // ProtoType
int count_words(char *word, char *sentece) {
	int result = 0;
    while(*sentece != '\0') {
    	int i = 0;
    	char buf[256];
    	while(*(sentece++) != ' ') buf[i] = *sentece;
    	if(strncmp(buf, word, i) == 0) result++;
    }
	return result;
}

int main() {
	
	char first[] = "Hello my name is noob hello hello  hello";
	char search[] = "hello";
	int times = count_words(search, first);
	printf("Word %s is %d times in %s! ",search, times, first);
}