CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    13

    occurence of alphabetic characters program

    I need help writing a program that will display the number of times each letter is used in the Gettysburg Address also naming the most commonly used letter. All I know is that I need to convert all of the lower case letters to uppercase. Help?

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: occurence of alphabetic characters program

    Well, assuming case invariance, there are 26 letters. That means you'll need 26 counters. While you might be tempted to use 26 if/else statements, it's much easier to just use an array of counters. Note: There will be non-letter characters in the document. You'll need to discard them, or otherwise handle them appropriately. The isalpha() function can help.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: occurence of alphabetic characters program

    Lindley is pointing you in the right direction. You just need an array size 26 to hold the count of each character. I don't believe I'd even use isalpha(). All you really need to do is convert each letter to the appropriate index for your counter array. This table should give you some clue how to do it. You should be able to write the whole counting algorithm in less than 10 lines of code. No need to convert case at all, at least not explicitly.

    http://www.asciitable.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured