|
-
April 8th, 2010, 10:40 PM
#1
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?
-
April 8th, 2010, 11:09 PM
#2
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.
-
April 9th, 2010, 07:48 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|