Question: I need help solving count_words() & count_numbers(). The language is C. ///////////////////////////////////////////////////////////////////////////////////////////////////////// Strings.h ///////////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef STRINGS_H #define STRINGS_H #include int count_words(const char *s); int count_numbers(const
I need help solving count_words() & count_numbers(). The language is C.
///////////////////////////////////////////////////////////////////////////////////////////////////////// Strings.h ///////////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef STRINGS_H #define STRINGS_H #include
int count_words(const char *s); int count_numbers(const char *s); #endif // STRINGS_H ///////////////////////////////////////////////////////////////////////////////////////////////////////// Challenge.c ///////////////////////////////////////////////////////////////////////////////////////////////////////// #include "strings.h"
#include
//1. Use additional string functions (strspn/strcspn) to help find and count certain patterns in strings.
// Suppose we wish to count maximum length contiguous // sequences of vowels in a string. This pattern of // code can do that. Make sure you understand it before // applying it in the two functions below. In at least // one of the cases it will need adaptation beyond changing // just the string of characters to match against. // Note how it succinctly checks for the "s is NULL" case. // Note also that experienced C programmers often omit // != 0 from a test, since it is redundant ... int count_vowel(const char *s) { int count = 0; const char *vowels = "aeiouy"; int temp; while (s && *s) { // skip if null, and stop at end of string s += (temp = strspn(s, vowels)); // temp gets match length s += strcspn(s, vowels); count += (temp != 0); } return count; } /////////////////////////////////////////////////////////////////////////////////////////////////////////
HELP WITH FOLLOWING FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Count words in a string. A "word" is a maximum length // contiguous sequence of characters that does not include // any of the delimiters space, tab, or newline. // @param s: The string for which the word count is desired // @result: The number of words in s; returns 0 if s is NULL int count_words(const char *s) { int count = -1; return count; }
// Count numbers in a string. A "number" is a maximum length // contiguous sequence of the digits 0 through 9. // @param s: The string for which the word count is desired // @result: The number of words in s; returns 0 if s is NULL int count_numbers(const char *s) { int count = -1; return count; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
