Thread: Counting characters

  1. #1
    Registered User
    Join Date
    Nov 2006

    Question Counting characters

    Does anyone know of a code I could use to count the number of characters (or words) in an externel text file? I suppose I would use the file to create a string variable first. but I can't think of what I'd use to count the characters (perhaps a search function of some sort?)

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Use the size() function member of the string to count the size of the string. Subtract the spaces by using the count() algorithm.

    Both functions description can be found here:
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Or if you're using Windows you could use CreateFile() to open a file and then GetFileSize() to get it's size.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the characters from each word from a text file
    By flipguy_ph in forum C Programming
    Replies: 6
    Last Post: 04-27-2009, 05:56 PM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. Help with hw problem: counting characters in a string
    By pinkfloyd4ever in forum C++ Programming
    Replies: 11
    Last Post: 11-04-2007, 11:18 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Counting characters
    By tay_highfield in forum C Programming
    Replies: 3
    Last Post: 01-29-2003, 12:54 PM