All pastes #63790 Raw Edit

Stuff

public text v1 · immutable
#63790 ·published 2006-06-10 17:45 UTC
rendered paste body
#include <stdio.h>


int mycmp(const char* s1, const char* s2);
int findChar ( char* source, char c );
int cnt = 0;
	
char message [] = "the cat sat on the mat the the the the";


int main (void)
{
 	char word, *msg;
	msg = message;
	word = 'h';
	

	cnt = findChar(msg, word);
	
	
	

	//printf("The word is: %s\n", word);
	//printf("the sentence is: %s\n", *message);
	printf("the word occurs %i times\n", cnt);

return 0;
}

int mycmp (const char* s1, const char* s2)
{
	while (*s1++ == *s2++);
	    return *s1 - *s2;
}

// find first occurence of character c in string source
int findChar ( char* source, char c ) {
	int len = strlen(source);
	int pos;
	int ocurrence = 0;
 
	for (pos = 0; pos < len; pos++) {
		if ( source[pos] == c )
			ocurrence++;
	}
 
	return ocurrence; // character c not found in string source
}