Thread: Counting Each Letter And Word In A File

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by Malcolm McLean View Post
    You want to create a histogram of all characters in a file. Characters are 8 bit, so the easiest way to do this is to declare a 256-member array of ints and initialise them all to zero. Then go through the file, as you are doing, and for each use the character as an index into the array, and increment it. There's no need to store the file in memory.
    Aren't you forgetting about multibyte charsets?

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    505
    Quote Originally Posted by flp1969 View Post
    Aren't you forgetting about multibyte charsets?
    He's reading the characters as bytes, so not supporting them.
    If you've a big alphabet, there's no simple efficient way of counting each character in standard C. If you use C++, there are several predefined container types you can use which will do the job.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 11-24-2012, 04:10 AM
  2. Counting specific word from file
    By donaldgx in forum C Programming
    Replies: 5
    Last Post: 04-13-2012, 09:00 PM
  3. Capitalize first letter of every word in .txt file
    By crazygopedder in forum C Programming
    Replies: 9
    Last Post: 10-15-2008, 12:09 PM
  4. strtok - word counting from a file
    By |PiD| in forum C Programming
    Replies: 4
    Last Post: 11-15-2002, 04:16 AM
  5. Problem with letter and word counting
    By wordup in forum C Programming
    Replies: 3
    Last Post: 10-09-2002, 04:02 PM

Tags for this Thread