472,805 Members | 3,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 1571
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.