Like Tree3Likes
  • 1 Post By tabstop
  • 1 Post By itsme86
  • 1 Post By Matticus

Hw Help PLEASE

This is a discussion on Hw Help PLEASE within the C# Programming forums, part of the General Programming Boards category; I am trying to count the number of words, lines, character, sentences. But I keep on messing up. I want ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    4

    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]
    Attached Files Attached Files
    • File Type: c wc.c (919 Bytes, 56 views)

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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.
    AndrewHunter likes this.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,164
    Code:
    string input = Console.ReadLine();
    int num_sentences = input.Where(c => c == '.').Count();
    AndrewHunter likes this.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    4

    None

    I know what i am doing. I just need some help! It in C language

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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?

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    4
    i get errors here
    Code:
    if (c= ".")
    	{	
    	++ns;
    	}

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    2,435
    You might find some answers here - read carefully, though. And start at post #2.
    AndrewHunter likes this.

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    4
    gee thanks

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    2,435
    I'm not trying to be a smart *** - that should literally help you solve your problem.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21