Any trick for calculate the number words in the text file?

01/07/2004 - 14:28 por Frank | Informe spam
for some reason, i have to write some code to calculate the number of words
which exists in the text file. the language of text is international. but,
at above of them, i wanna write some code to figure the western language
out. but, i really cannt get any trick or idea for it. so, i wrote this post
to ask for some helps. any reply is appreciated :-)

Frank F.Han

+--+
| winsays@:-)hotmail:-).com |
+--+

Preguntas similare

Leer las respuestas

#1 TVR Fan
01/07/2004 - 16:03 | Informe spam
"Frank" wrote in message
news:%23$
for some reason, i have to write some code to calculate the number of


words
which exists in the text file. the language of text is international. but,
at above of them, i wanna write some code to figure the western language
out. but, i really cannt get any trick or idea for it. so, i wrote this


post
to ask for some helps. any reply is appreciated :-)



I don't really understand what you are asking in terms of languages. If you
are trying to ascertain the language from the text, I suppose you could
search for joining words: if the file contains lots of 'the', 'and', 'then',
'to' etc then it's English. 'le', 'la', 'en' etc indicate French and so on.

Do you have to write your own program to counting words? Linux & Unix
systems have a command 'wc' which gives a word count for a given file. I'm
sure you can download a Windows version of the same. MS Word has a Word
Count option under the Tools menu.

If you really do need to do it in code, two ways spring to mind:
you could use the system() C library function to run the wc command and
redirect its output to a file?
Or do the counting yourself: open a CFile object, read each line and use
strchr() to loop though the line looking for space characters.

Either way, I don't think this is really an MFC question is it?

Al.
Respuesta Responder a este mensaje
#2 Rufus V. Smith
01/07/2004 - 19:25 | Informe spam
"TVR Fan" wrote in message
news:
"Frank" wrote in message
news:%23$
> for some reason, i have to write some code to calculate the number of
words
> which exists in the text file. the language of text is international.


but,
> at above of them, i wanna write some code to figure the western language
> out. but, i really cannt get any trick or idea for it. so, i wrote this
post
> to ask for some helps. any reply is appreciated :-)

I don't really understand what you are asking in terms of languages. If


you
are trying to ascertain the language from the text, I suppose you could
search for joining words: if the file contains lots of 'the', 'and',


'then',
'to' etc then it's English. 'le', 'la', 'en' etc indicate French and so


on.

Do you have to write your own program to counting words? Linux & Unix
systems have a command 'wc' which gives a word count for a given file. I'm
sure you can download a Windows version of the same. MS Word has a Word
Count option under the Tools menu.

If you really do need to do it in code, two ways spring to mind:
you could use the system() C library function to run the wc command and
redirect its output to a file?
Or do the counting yourself: open a CFile object, read each line and use
strchr() to loop though the line looking for space characters.

Either way, I don't think this is really an MFC question is it?

Al.



I'm just learning awk, here's some code:

Word count:

gawk "{ words += NF } END {printf(\"word count = %d\",words)}" filename.txt

Line count even easier:

gawk "END {printf(\"line count = %d\",NR)}" filename.txt

Share and Enjoy!

Rufus
Respuesta Responder a este mensaje
#3 TVR Fan
02/07/2004 - 11:48 | Informe spam
I'm just learning awk, here's some code:

Word count:

gawk "{ words += NF } END {printf(\"word count = %d\",words)}"


filename.txt

Line count even easier:

gawk "END {printf(\"line count = %d\",NR)}" filename.txt



Indeed, it is very easy in awk but if the OP just wanted a program to count
words then downloading a version of wc is even easier!
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida