Hey guys i was wondering if any of you could help here. I've looked around the forums and found a few topics on word_count, the problem is that they use codes that my class hasn't gone into yet so i cant use either.
My problem is that we are supposed to make a program that let's us input a sentence, then it will show the letter count, write the letters 1 letter per line, then show word count.
I was able to do the 1st 3 but for some reason my program wont print the number of words, it's always 0. Can anyone help me out?
#include <stdio.h>
#include <ctype.h>
void input(char *str);
int Ecount(char *str);
void Display(char *str);
void Wcount(char *str);
void main(void)
{
char S[50];
int count;
printf("Input a string: ");
input(S);
count = Ecount(S);
printf("There are %d number of characters.", count);
printf("\n\n");
Display(S);
Wcount(S);
}
void input(char *str)
{
int i=-1;
do
{
i++;
scanf("%c", &str[i]);
}
while (str[i] !='\n');
str[i]='\0';
}
int Ecount(char *str)
{
int i;
i=0;
while (str[i] !='\0')
i++;
return i;
}
void Display(char *str)
{
int i;
i=-1;
while (str[i] !='\0')
{
i++;
printf("%c\n", str[i]);
}
}
void Wcount(char *str)
{
int i=0, word_count=0;
while (str[i] !='\0')
i++;
{
if( isspace(str[i]) && !isspace(str[i+1]))
word_count++;
i++;
printf("\nThere are %d words.", word_count);
}
}