Char

This is a discussion on Char within the C++ Programming forums, part of the General Programming Boards category; hey, ummm, i wanna know what happens, when a character is entered.....does it turn into a number?? what?? ha, idk, ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    30

    Char

    hey, ummm, i wanna know what happens, when a character is entered.....does it turn into a number?? what?? ha, idk, im confused, plz help me
    ADRUMSOLO4U

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    or just sit there, and wonder at my stupidity
    ADRUMSOLO4U

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    Well, I'm not sure that your question was worded extremely well, but of course a character doesn't become an integer just because.
    --LiKWiD
    Becoming un-noobified one day at a time.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    well...hmmm....lets say you enter the letter "a"....what is that to the computer? does it equal "a"?
    ADRUMSOLO4U

  5. #5
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    It stays a character untill you cast it or make it into something else
    Code:
    char character = 'L'
    
    cout << int(character) << endl;
    // this will display the character, in this case 'L' as a number
    // if you wanna know what happens try it yourself!

    EDIT:

    knowing this will display the ASCII character for 'L' you can make a program that will display the ASCII number for every character from ASCII and also the ones that you have to press 'alt' + [numbers on the number pad] and makes weird characters... so then youll know what combination makes what character.

    I had a program like that one time..
    Last edited by mrafcho001; 03-21-2005 at 05:51 PM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    yea, you see, what im doing is, im trying to make an encrypter, to code a sentence...and also the vice-varsa to decrypt it, of course

    im also gonna need to know what a space comes out to be....so that when it is encryted the program doesnt go crazy
    Last edited by adrumsolo4u; 03-21-2005 at 06:01 PM.
    ADRUMSOLO4U

  7. #7
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    build the program i told, the one that displays all the numbers from 0 - 255 into ASCII characters.. those are all the ASCII characters. and then youll know what is what..

    That will help you

  8. #8
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    If you want to simply make it unreadable by your friends, output the characters to your file as mrafcho001 said, then create a program to 'decode' the same. I believe you can find what a space is by replacing 'L' with ' '.


    EDIT: As he said.
    --LiKWiD
    Becoming un-noobified one day at a time.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    Code:
    int main(){
        cout<<"Please Enter a sentence no longer than 50 letters, and use only lower-case letters, please:/n";
        char sentence(51);
        int A;
        for(A=0; A>50; A++){
            if(sentence(A)=97){
                sentence(A)=01;
            }
        }
    }
    that is what im trying to do...well, part of it anyway....it keeps saying sentence cannot be used as a function...but im not trying to...

    btw, 97 is the lower-case ansi version of "a"
    Last edited by adrumsolo4u; 03-21-2005 at 06:26 PM.
    ADRUMSOLO4U

  10. #10
    Registered User
    Join Date
    Mar 2005
    Posts
    7
    sentence(A) is trying to call sentence() as a function. You want to use it as an array, so you'd use
    Code:
    sentence[A]

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    oh crap, lol, i forgot about that!!! woa....im realy out of it today
    ADRUMSOLO4U

  12. #12
    Registered User
    Join Date
    Mar 2005
    Posts
    7
    Don't worry 'bout it... happens to the best of us... Also, you're not setting anything to your array 'sentence'... regardless of what they enter, without something to catch the input, you'll get nothing back... don't forget good ol' cin function.

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    oh yea.....should i use cin for characters though? i dont want numbers
    man, im such a noob at this, lol
    ADRUMSOLO4U

  14. #14
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Remeber if they enter a space in the sentece the string will only remember everything before the first space... so use
    Code:
    char blah[51];
    cout << "input sentece: ";
    cin.getline(cin, blah);
    just a note

    EDIT:

    BTW you should use strings:

    Code:
    #include <string>
    // blah blah
    
    string sentence;
    cout << "input sentece: ";
    cin.getline(cin, sentence);
    
    //this will input everything in the string including the spaces..
    
    //O wait.. i am not sure you can access every character in the string separately.. so you might wann stick with arrays..
    
    
    //God what a pointless 'EDIT:' :)
    Last edited by mrafcho001; 03-21-2005 at 07:07 PM.

  15. #15
    Registered User
    Join Date
    Jan 2005
    Posts
    30
    wow, that helped alot, i almost threw my compter out the window, because i was using just cin.....and it didnt work
    ADRUMSOLO4U

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 07:02 AM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 08:36 AM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 10:22 AM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM

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