Thread: writing characters...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    77

    writing characters...

    I am having trouble figuring out how to store a letter into a variable of the type char. I have an example of some code below. Thanks in advance.
    JK

    Code:
    #define  number_of_letters 6
    char letter;
    enum type_of_letter
    {
    a,
    b,
    c,
    d,
    e,
    f
    }
    
    for (i=0; i<number_of_letters; i++)
    {
    letter = ??? //want to copy the letter found in "type_of_letter" to letter.
    }

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Ummmm, that really isnt the way to go. Try using an array instead because enums are only integers (correct me if Im wrong), so in your code type_of_letter::a would be 0 I believe. Try something like this:
    Code:
    // bla bla bla
    char type_of_letter[number_of_letters] = {'a','b','c','d','e','f'};
    
    for (i=0; i<number_of_letters; i++)
    {
    letter = type_of_letter[i]
    }
    At least I guess this is what you want.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    77

    Cool

    thank you that worked very well!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the characters from each word from a text file
    By flipguy_ph in forum C Programming
    Replies: 6
    Last Post: 04-27-2009, 05:56 PM
  2. ascii characters video displaying on tv screen
    By deian in forum C Programming
    Replies: 6
    Last Post: 10-12-2004, 09:46 PM
  3. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM
  4. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM