diff --git a/xtandard.c b/xtandard.c index d86668c..29723ca 100644 --- a/xtandard.c +++ b/xtandard.c @@ -573,31 +573,25 @@ int character_compare_array (char character, char * character_array) { return (0); } -int character_count (char * string, int from, int to, char this, char stop) { +int character_count (char * string, char this, int from, int to, char stop) { int count; + for (count = 0; (from != to) && (string [from] != stop); from += (int) ((to < from) ? -1 : 1)) { + count += (int) ((string [from] == this) || (this == '\0')); + } +/* if (to < from) { - for (count = 0; to < from; --from) { - if ((string [from] == this) || (this == '\0')) { - ++count; - } - if (string [from] == stop) { - break; - } + for (count = 0; (to < from) && (string [from] != stop); --from) { + count += (int) ((string [from] == this) || (this == '\0')); } } else if (from < to) { - for (count = 0; from < to; ++from) { - if (string [from] == this) { - ++count; - } - if (string [from] == stop) { - break; - } + for (count = 0; (from < to) && (string [from] != stop); ++from) { + count += (int) ((string [from] == this) || (this == '\0')); } } else { count = 0; } - +*/ return (count); } diff --git a/xtandard.h b/xtandard.h index cc3c159..ce02af2 100644 --- a/xtandard.h +++ b/xtandard.h @@ -106,7 +106,7 @@ extern int character_is_hexadecimal (char character); extern int character_compare_array (char character, char * character_array); -extern int character_count (char * string, int from, int to, char this, char stop); +extern int character_count (char * string, char this, int from, int to, char stop); extern int string_length (char * string);