Computer Science Canada Sorting from a file |
Author: | marshymell0 [ Mon Apr 24, 2006 9:13 pm ] | ||||||
Post subject: | Sorting from a file | ||||||
Ok..the problem I'm having is basically, I don't know where to start. Basicially, a program is made in which a text file is examined, and the results of the file is shown. The results show specific results, such as how many consonants, which constants were in the file, speical symbols, etc. For example, if the text file is
My output would be 4 numbers total, numbers are 2,3,6 and 3 letters, which are W,E,e, and 2 speical symbols are ^,$ My friend taught me how to open the file, etc. This is what the code looked like.
Now, for the actual sorting, this is what I'm sorta thinking. Can I have a for loop, in which I go from like characters a-Z, whatever ASCII values those are, and set is as a boolean. So, if chr (x)=A, then I add one to the storage array for the letter "A"
That sort of the basic idea, but the problem is u can't have the chr(x)=true. store (x) end for [code] |
Author: | NikG [ Mon Apr 24, 2006 10:31 pm ] | ||
Post subject: | |||
Sorry, I don't have much time right now to give a full response, but here's something that might help you if you're going to be using for loop comparisons. The for loop is actually more capable than you think:
|
Author: | NikG [ Mon Apr 24, 2006 10:49 pm ] | ||
Post subject: | |||
Sorry about the vague previous response, I have a few more minutes now. You don't need an array. All you need is 3 string variables: one for the numbers, one for the letters, one for the special characters. Then go through each character of each line and keep adding the character to one of the strings depending on which test it passes:
|