473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Text word count c++

Hello everyone, around one weeek ago i started to learn the c++
language. And i try to solve different programs i found from a text
book i got here in greece. But i got to a chapter and i have met a
program that wants me to count the words from an input text but not
using UTF-8 of UTF-7 but ASCII.. does anyone knows how to help me. ? I
have tryed many things but i have managed only to print out the ascii
number of each letter of a word.. nothing more....
again if anyone knows please help...

Thank you

Samuel
Jan 27 '08 #1
1 2307
On 2008-01-27, Alf P. Steinbach <al***@start.nowrote:
* samoukos:
>Hello everyone, around one weeek ago i started to learn the c++
language. And i try to solve different programs i found from a text
book i got here in greece. But i got to a chapter and i have met a
program that wants me to count the words from an input text but not
using UTF-8 of UTF-7 but ASCII.. does anyone knows how to help me. ? I
have tryed many things but i have managed only to print out the ascii
number of each letter of a word.. nothing more....
again if anyone knows please help...

It depends very much on the definition of "word".

If you can accept the definition that's implicit in using >>, then just
use >(on std::cin) to input the words.
The following program implements that idea (code taken out from my
Sandbox, slightly adapted from TICPP):

#include <iostream>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

int main (int argc, char** argv) {
int num = 0;
string word;
string filename;

if (argc < 2) {
cerr << "Usage: " << argv[0] << " <filename>" << endl;
exit(1);
}
filename=argv[1];

ifstream in(filename.c_str());

while (in >word) {
cout << word << endl;
num++;
}

cout << num << endl;
exit(0);
}

Regards.
--
Stefano Sabatini
Linux user number 337176 (see http://counter.li.org)
Feb 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: dan | last post by:
this is a program to count average letters per word. i am able to count the total number of letters, but not words. How do you count the total number of words in a text file, so i am able to divide...
1
by: jeguillo | last post by:
I am trying to retrieve the text within each cell in a datagrid in order to change the color of each cell, depending on the value within that cell. This works fine on the cells that are bound...
3
by: sb Luis | last post by:
I Use the following code to read from MS Word, but I couldent read Formated Text (RTF). How Can I read formated text from MS Word Doc without using clipboard. thanks. Word.ApplicationClass...
8
by: FUGATO | last post by:
I need to help in my assignment. I need to wrap a text with the following indications: 1.If you have reached the end of the line (number of characters on this line >= 40) AND you have reached the...
4
by: bigbagy | last post by:
Notes The programs will be compiled and tested on the machine which runs the Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used. A significant amount coding is...
1
by: Darsin | last post by:
What i am doing is to pull the data from a CMS and import it to Word 2007 Beta and i also have to export the data from Word 2007 Beta back to that CMS. We have with us two Web Services of the CMS....
10
by: Johny | last post by:
I need to find all the same words in a text . What would be the best idea to do that? I used string.find but it does not work properly for the words. Let suppose I want to find a number 324 in...
0
by: JosAH | last post by:
Greetings, Introduction Last week I started thinking about a text processing facility. I already found a substantial amount of text: a King James version of the bible. I'm going to use that...
2
by: beanie | last post by:
i am a beginer in c programming and i am trying to Create a Concordance of Word Count for a Text File but my code is not working.pls can anyone helpme out.here is my code: #include <stdio.h>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.