array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • help1267
    New Member
    • Aug 2006
    • 10

    array

    Hi,

    Instead of:
    char let[26] = {'A','B','C','D ','E',...., 'Z''};

    What would be another (shorter) way of writing this ?

    Thx,
  • rgb
    New Member
    • Aug 2006
    • 37

    #2
    this is dependent on your character set (ASCII will work), you can declare a char data type initialized at first letter of the aplphabet and then increment it (ex. i++) for the next letter on a loop.

    Comment

    • help1267
      New Member
      • Aug 2006
      • 10

      #3
      Hi rgb,
      thanks for your reply. I'm new at this. Would you be able to elaborate ?

      Thx,

      Comment

      • D_C
        Contributor
        • Jun 2006
        • 293

        #4
        Banfa mentioned in an earlier post, that only 0-9 are guaranteed to be consecutive, although as is the case for ASCII, a-z are consecutive, as well as A-Z.

        With your array, let[0] = 'a', let[25] = 'z'. For 0 <= N <= 25, you could replace let[N] with ('a'+N)

        Comment

        • rgb
          New Member
          • Aug 2006
          • 37

          #5
          Originally posted by D_C
          Banfa mentioned in an earlier post, that only 0-9 are guaranteed to be consecutive, although as is the case for ASCII, a-z are consecutive, as well as A-Z.
          as mentioned, the approach is dependent on the charater set. i am not familiar with other sets, most of the time i use ASCII character set.

          Comment

          • rgb
            New Member
            • Aug 2006
            • 37

            #6
            Originally posted by help1267
            Hi,

            Instead of:
            char let[26] = {'A','B','C','D ','E',...., 'Z''};

            What would be another (shorter) way of writing this ?

            Thx,

            you can also use this approach:

            char let[ ] = "ABCDEF...X YZ";

            the array let[ ] will be indexed the same as yours.

            let[0] will be equal to 'A'
            let[1] will be equal to 'B'
            etc
            etc
            etc
            let[25] will be equal to 'Z'

            Comment

            • Talon4196
              New Member
              • Dec 2006
              • 2

              #7
              char let[26];
              for (int x = 65; x < 91; x++)
              let[x-65] = char(x);

              Comment

              • Talon4196
                New Member
                • Dec 2006
                • 2

                #8
                well.. instead of 65, and 91, just use int('A') and int('Z')... 65 and 91 is what the values are for my keyboard...

                Comment

                Working...