-
1 Attachment(s)
Hw Help PLEASE
I am trying to count the number of words, lines, character, sentences. But I keep on messing up. I want to tell it to count the number of periods and make that a sentence, but I am having trouble.
Code:
[tag]#include <stdio.h>
int
main( void )
{
unsigned long nl = 0UL; /* #lines */
unsigned long nw = 0UL; /* #words */
unsigned long nc = 0UL; /* #chars */
unsigned long ns= 0UL; /* #sents*/
int c;
int inword = 0; /* true only when inside a word */
while ( (c = getchar()) != EOF )
{
++nc;
if ( c == '\n' )
{
++nl;
}
if ( c == ' ' || c == '\n' || c == '\t'
|| c == '\r' || c == '\v' || c == '\f' )
{
/* if whitespace, we're not inside a word */
inword = 0;
}
if (c= ".")
{
++ns;
}
else if ( !inword )
{
inword = 1;
++nw;
}
}
printf( "%lu lines, %lu words, %lu chars %lu sents\n", nl, nw, nc, ns );
return 0;
[/tag]
-
1. You appear to have missed out what language you are using.
2. Compare c == '\n' and c == ' ' etc with the line c= ".", which should be a compile error/warning anyway.
-
Code:
string input = Console.ReadLine();
int num_sentences = input.Where(c => c == '.').Count();
-
None
I know what i am doing. I just need some help! It in C language
-
1. You shouldn't take people's signatures as personal remarks (i.e., as remarks directed to you).
2. If it is in the C language, why did you post it in the forum for the C# language (which is really rather removed from C)?
3. Did you read any of the posts above where the help was given?
-
i get errors here
Code:
if (c= ".")
{
++ns;
}
-
You might find some answers here - read carefully, though. And start at post #2.
-
-
I'm not trying to be a smart *** - that should literally help you solve your problem.