Thread: c++

  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
    London, United Kingdom
    Posts
    226
    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