1 /* 2 * how_many.c 3 * 4 * written by Joshua J. Drake 5 */ 6 7 #include "how_many.h" 8 9 /* 10 * count how many ch's are in str.. 11 * ..but!, don't count repeated spaces 12 */ 13 14 15 int how_many(u_char * str,u_char ch)16how_many(u_char *str, u_char ch) 17 { 18 int count = 0; 19 u_char *ptr = str; 20 21 while (*ptr) 22 { 23 if (*ptr == ch) 24 { 25 if (ch == ' ') 26 { 27 if (ptr - str > 0 && *(ptr - 1) != ' ') 28 count++; 29 } 30 else 31 count++; 32 } 33 ptr++; 34 } 35 return count; 36 } 37