Transforming letters to numbers...

This is a discussion on Transforming letters to numbers... within the C++ Programming forums, part of the General Programming Boards category; -> I'm quite new to C++! -> How can I change letters (Abc), which I enter into a string, into ...

  1. #1
    N8760
    Guest

    Arrow Transforming letters to numbers...

    -> I'm quite new to C++!

    -> How can I change letters (Abc), which I enter into a string, into fixed numbers, like A->1, B->2....Z->26, so that I get two arrays, e.g. char alpha[26] and int num[26]. Thank you very much!

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    60
    /* Say letter is filled with 'A', 'B', ... */

    char letter[26];
    int numb[26];
    for(int i=0;i<26;i++)
    numb[i]=letter[i]-'A'+1;

    /* I hope this is a proper answer */

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    10

    thanks

    thank you very much!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Count number of letters and numbers in a file
    By jtullo in forum C Programming
    Replies: 2
    Last Post: 04-21-2008, 02:33 AM
  2. Generate Random Numbers and Assign to Days of Week
    By mms in forum C++ Programming
    Replies: 10
    Last Post: 05-04-2006, 02:51 AM
  3. Replies: 4
    Last Post: 04-19-2005, 09:05 PM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. How do you allocate numbers to letters?
    By face_master in forum C++ Programming
    Replies: 9
    Last Post: 11-14-2001, 06:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21