c++

This is a discussion on c++ within the C++ Programming forums, part of the General Programming Boards category; i am trying to write a function word(istream&, char*)that counts the words from the input file. how to proceed? p ...

  1. #1
    Unregistered
    Guest

    Question c++

    i am trying to write a function word(istream&, char*)that counts the words from the input file.
    how to proceed? p lease suggest anybody.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    I suggest finding your textbook. Open at the relevent page and then read. Might work. If not, post some code.

  3. #3
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    Munich, Germany
    Posts
    224
    1. Check every character of the input stream one after the other.

    2. If any of the characters is " " (space) and the next one is not " " space...increment the variable 'words' by 1.

    e.g.

    for (int i=0;i!=(total_file_size_in_bytes);i++)
    if (letter[i] == ' ' && letter[i+1] != ' ')
    wordcount++;

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