Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please give me the whole source code in C : The countWords() function from Progr

ID: 3921420 • Letter: P

Question

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] = '';
}

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

for ( i = 0; string[i] != ''; ++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] == '' )
endOfText = true;
  
  
else
totalWords += countWords (text);
}

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

return 0;

Explanation / Answer

#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] = '';
}
int countWords (const char string[])

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