473,608 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is there an existing library for counting characters?

36 New Member
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 1622
sicarie
4,677 Recognized Expert Moderator Specialist
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 Recognized Expert MVP
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
fressanme
36 New Member
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 Recognized Expert Contributor
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
fressanme
36 New Member
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
3041
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 KA}\N{DEVANAGARI VOWEL SIGN AA}\N{DEVANAGARI LETTER KA}" )
6
1561
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 which the user may easily extend. It also tries to solve few problems which exist in the standard string and have been discussed during the recent years in the various newsgroups. The library may be downloaded freely from:
5
2003
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 avail. Can somebody explain to me what this does?: #include <stdio.h> /* count characters in input; 2nd version */ main() {
1
6914
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 with uploaded MS WORD .doc files. Using code like that below: strLine = sr.ReadLine While Not IsNothing(strLine) 'Not eof If Trim(strLine) <> "" Then 'Not blank
3
1867
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 represented as '\n' 2. a tab as '\t' 3. a space as ' '
4
2651
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
2776
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 character is added like some language specific char. How to count specials like 1 char? tnx
23
1771
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 me the Standard C++ Library have headers to mainipulate
8
5267
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 <iostream> #include <cstring> #include <fstream> #include <conio.h> #include<stdio.h> #include <string.h>
0
8491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8470
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8142
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8329
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6010
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4022
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1327
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.