473,387 Members | 1,834 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,387 software developers and data experts.

is there an existing library for counting characters?

i would like to ask if there is an existing algorithm for counting characters from a text file?

if there is,can i have a sample?
Feb 2 '08 #1
5 1608
sicarie
4,677 Expert Mod 4TB
There is an algorithm - open the file, get a line, count each character in the file while the character is not the EOF char.
Feb 2 '08 #2
JosAH
11,448 Expert 8TB
If you're running a POSIX compliant system (MS Windows claims it is) just have
a look at the fstat() function; that's all you need then; no need for reading
the entire file and counting every single byte.

kind regards,

Jos
Feb 2 '08 #3
There is an algorithm - open the file, get a line, count each character in the file while the character is not the EOF char.
how do i know its an EOF?what do i tell the program?and how should i put it if its the EOL char and i want the reader to go down to the next line?
Feb 2 '08 #4
oler1s
671 Expert 512MB
how do i know its an EOF?
Depends on the language and how you read from the file. You neglected to mention what language you are using....on a programming question.

You can always find out how to determine EOF on your own. The languages and their standard libraries are documented. That means you can just Google up the documentation and read how to detect EOF.

Once you figure out the logic to detecting an EOF, obviously write the appropriate code for it.

and how should i put it if its the EOL char and i want the reader to go down to the next line?
Lines are nothing but blocks of text marked at the end by a newline character. The reader has no concept of "down". Computers are not humans. They don't open up a file on Microsoft windows and stare at a monitor. They see a continous stream of bytes of the computer, and interpret them as you tell them to.

Expand|Select|Wrap|Line Numbers
  1. This is a line.\nThis is another line.\n\nNow a new paragraph.\nWith a second line.\nEOF
There's 86 "characters" on that example above. But you would actually omit the '\n' newline characters and EOF from your calculation.

But again, the actual logic you need to code depends on the language and what I/O functions you use to read the file.
Feb 2 '08 #5
Depends on the language and how you read from the file. You neglected to mention what language you are using....on a programming question.

You can always find out how to determine EOF on your own. The languages and their standard libraries are documented. That means you can just Google up the documentation and read how to detect EOF.

Once you figure out the logic to detecting an EOF, obviously write the appropriate code for it.

Lines are nothing but blocks of text marked at the end by a newline character. The reader has no concept of "down". Computers are not humans. They don't open up a file on Microsoft windows and stare at a monitor. They see a continous stream of bytes of the computer, and interpret them as you tell them to.

Expand|Select|Wrap|Line Numbers
  1. This is a line.\nThis is another line.\n\nNow a new paragraph.\nWith a second line.\nEOF
There's 86 "characters" on that example above. But you would actually omit the '\n' newline characters and EOF from your calculation.

But again, the actual logic you need to code depends on the language and what I/O functions you use to read the file.
this is a C++ forum so im using this kind of language..i guess theres no need to mention that.. :D

thanks for the info..i'll try working on it right away..thanks a lot.. :)
Feb 3 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Srinath Avadhanula | last post by:
Hello, I am wondering if there is a way of counting graphemes (or glyphs) in python. For example, in the following string: u'\u0915\u093e\u0915' ( or equivalently, u"\N{DEVANAGARI LETTER...
6
by: shablool | last post by:
Hi all! The Strinx library is an efficient and easy-to-use string library. It is written in C++, using modern template approach. It uses a class hierarchy to implement a set of string objects...
5
by: Matt | last post by:
Alright, so I'm a little confused here...what exactly does this do? I've run it and it doesn't display anything, so I've typed some things into it, to see if it'd do something then, but to no...
1
by: j | last post by:
Hi, I've been trying to do line/character counts on documents that are being uploaded. As well as the "counting" I also have to remove certain sections from the file. So, firstly I was working...
3
by: arnuld | last post by:
this is an example programme that counts lines, words and characters. i have noticed one thing that this programme counts space, a newline and a tab as a character. i know: 1. a newline is...
4
by: Herman.Schultz | last post by:
Hi, How can I use iostream library in c++ to copy a file from i th byte to an output file? Thank you.
3
by: majna | last post by:
I have character counter for textarea wich counting the characters. Special character needs same place as two normal characters because of 16-bit encoding. Counter is counting -2 when special...
23
by: June Lee | last post by:
is it true that Standard C++ Library is pretty much include functions similar to the following java packages??? java.io java.lang java.util http://www.cplusplus.com/reference/ It seem to...
8
by: xiaolim | last post by:
i making a simple program to count the different kinds of characters in a text file and then display them out, however i only manage to count the total numbers of characters. #include...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.