Looping Problem

This is a discussion on Looping Problem within the C++ Programming forums, part of the General Programming Boards category; Can anyone help me with this looping program. I need to develop a program that prints out the approximate number ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Looping Problem

    Can anyone help me with this looping program. I need to develop a program that prints out the approximate number of words in a file of text. I want to include the gaps between the words also. I am going to echo print the the data to the user. I know a loop is going to be used to make the program easier to develop. If anyone has something that can be of some use to me I will be checking the thread throughout the day. Also if you have any questions I will get back to them ASAP.

    Thanks

  2. #2
    Unregistered
    Guest
    hope this helps a little:

    #include<fstream.h>
    #define WHT_SPC (cur==' '||cur=='\n'||cur=='\t')

    int main (void)
    {
    char cur;
    char word='O'; //O out of a word: I in a word
    int countWd=0;
    ifstream fsInFile;

    fsInFile.open ("file.dat") //whatever the file is
    if (!fsInFile)
    {
    cerr<<"error opening file.";
    exit(100);
    }
    while (fsInFile.get (cur))
    {
    if(WHT_SPC)
    word='O';
    else
    if(word=='O')
    {
    countWd++;
    word='I';
    }
    }

    cout<<"Number of words: "<<countWd;
    fsInFile.close();

    return0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  2. looping problem
    By chris285 in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 11:03 AM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Looping problem
    By sketchit in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 02:19 PM

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