Thread: Counting the number of words input

  1. #1
    Registered User
    Join Date
    Dec 2011

    Lightbulb Counting the number of words input

    I am trying to count the number of words the user inputs and print out the input and show how many words were used, there are multiple problems that are mentioned in the tabs.
    Last edited by lostnthestars; 12-18-2011 at 05:43 PM.

  2. #2
    Registered User
    Join Date
    Dec 2011
    namespace std;
     main(int argc, char *argv[])
    int nos = 0;   // Number of strings in the users input.
    int nsc = 0;   // Number of strings counted.
    int start = 0; // Starting int
        string nui = 
    "";    // All the strings together
    while (nos == start)
              string ui;   
    // Users input
              cout << 
    "Type something" << endl;        // Self explained
              cin >> ui;    
    // Users input
    // +1 to nos
    while ((nos > start) && (nos > nsc))        // while nos > nsc continue running this is where im having my problem
    // insted of using > < is there another way to let the program know if 
                    ui +=nui;       
    // + ui to nui      // there is another string to be added continue running?
    // +1 to nsc
    // Prints out the final results, also this part does not print out at all at the end of the program.
        cout << 
    "Your string was - " << nui << " - and it had - " << nsc << " - words in it." <<
    return EXIT_SUCCESS;

  3. #3
    Join Date
    Oct 2007
    Inside my computer
    I have no idea what your code is doing (it's also formatted very badly on the board, what did you do?).
    However, if you want to count the number of words a user inputted, it should be as simple as counting the number of spaces. Number of spaces + 1 == number of words, wouldn't you agree?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-05-2010, 03:04 AM
  2. Counting input words
    By Soulrivers in forum C++ Programming
    Replies: 26
    Last Post: 01-17-2008, 03:06 PM
  3. Counting Number of Words in a Text File Using C
    By wvu2005 in forum C Programming
    Replies: 16
    Last Post: 09-27-2005, 11:45 AM
  4. counting the number of words
    By ccoder01 in forum C Programming
    Replies: 3
    Last Post: 05-29-2004, 02:38 AM
  5. counting the number of words in a file
    By stuartbut in forum C Programming
    Replies: 2
    Last Post: 04-13-2002, 08:19 AM