Count number of letters and numbers in a file

This is a discussion on Count number of letters and numbers in a file within the C Programming forums, part of the General Programming Boards category; Hello, I wanted to know if there is a better way to code this situation of counting the number of ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    11

    Count number of letters and numbers in a file

    Hello,

    I wanted to know if there is a better way to code this situation of counting the number of occurances of each letter(case insensitive) and each number in a file, disregarding other characters. So far I have it completed by turning each line of the file into a string, than using loops, if-else logic, and isalpha and isdigit to walk through each string char by char to do this, updating as i go along. My question is there a simpler code to do this? I am fairly new to C programming. Thanks for help.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Yes, don't bother breaking it up into lines for one.

    Without seeing how you're doing it, it's hard to say.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    I'm thinking you might need an array and some char logic to use it as a map.
    Code:
    char counts[255] = {0};
    counts['a']++;
    counts['9']++;
    Etc.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to use case/switch with letters and numbers
    By jericjones45 in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 04:38 PM
  2. need to count individual letters in input
    By epox in forum C Programming
    Replies: 12
    Last Post: 05-22-2006, 06:32 AM
  3. converting numbers to letters??
    By Lau in forum C Programming
    Replies: 5
    Last Post: 11-06-2002, 11:17 AM
  4. Convert Phone Letters To Numbers
    By nicolobj in forum C Programming
    Replies: 4
    Last Post: 10-03-2002, 03:53 PM
  5. Transforming letters to numbers...
    By N8760 in forum C++ Programming
    Replies: 2
    Last Post: 12-23-2001, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21