please give me the whole source code in C The countWords fu

please give me the whole source code in C :

The countWords() function from Programs 9.7 and 9.8 incorrectly counts a word that contains an apostrophe as two separate words. Modify this function to correctly handle this situation. Also, extend the function to count a sequence of positive or negative numbers, including any embedded commas and periods, as a single word.

function 9.8:

#include <stdio.h>
#include <stdbool.h>

bool alphabetic (const char c)
{
if ( (c >= \'a\' && c <= \'z\') || (c >= \'A\' && c <= \'Z\') )
return true;
else
return false;
}

void readLine (char buffer[])
{
char character;
int i = 0;

do
{
character = getchar ();
buffer[i] = character;
++i;
}
while ( character != \'\ \' );

buffer[i - 1] = \'\\0\';
}

int countWords (const char string[])
{
int i, wordCount = 0;
bool lookingForWord = true, alphabetic (const char c);

for ( i = 0; string[i] != \'\\0\'; ++i )
if ( alphabetic(string[i]) )
{
if ( lookingForWord )
{
++wordCount;
lookingForWord = false;
}
}
else
lookingForWord = true;

return wordCount;
}

int main (void)
{
char text[81];
int totalWords = 0;
int countWords (const char string[]);
void readLine (char buffer[]);
bool endOfText = false;

printf (\"Type in your text.\ \");
printf (\"When you are done, press \'RETURN\'.\ \ \");

while ( ! endOfText )
{
readLine (text);

if ( text[0] == \'\\0\' )
endOfText = true;
  
  
else
totalWords += countWords (text);
}

printf (\"\ There are %i words in the above text.\ \", totalWords);

return 0;

Solution

#include &lt;stdio.h&gt;
#include &lt;stdbool.h&gt;
bool alphabetic (const char c)
(c &gt;= \'A\' &amp;&amp; c &lt;= \'Z\') )
return true;
else
return false;

void readLine (char buffer[])

while ( character != \'\ \' );
buffer[i - 1] = \'\\0\';
}
int countWords (const char string[])

}
else
lookingForWord = true;
return wordCount;
}
int main (void)

please give me the whole source code in C : The countWords() function from Programs 9.7 and 9.8 incorrectly counts a word that contains an apostrophe as two sep
please give me the whole source code in C : The countWords() function from Programs 9.7 and 9.8 incorrectly counts a word that contains an apostrophe as two sep

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site