the entered character is a lowercase, uppercase, or a real number

This is a discussion on the entered character is a lowercase, uppercase, or a real number within the C++ Programming forums, part of the General Programming Boards category; Please x 20 do NOT rely on ASCII. Don't mention it. Don't assume it is used. Don't even think about ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,010
    Please x 20 do NOT rely on ASCII. Don't mention it. Don't assume it is used. Don't even think about it.
    The C++ standard does not guarantee what the "underlying character set" is. It could be ASCII, but it could also be something entirely different.
    Furthermore, ASCII is an old american-only system. It needs to go away. Unicode is the new future as it is now.
    So again, don't assume ASCII, and throw away your ASCII table.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Mar 2011
    Posts
    254
    Thanks a lot, laserlight. It was helpful.

    Quote Originally Posted by laserlight View Post
    Incidentally, though it does not matter in practice these days, in theory the English letters in the character set need not be in contiguous and in alphabetical order. You do have this guarantee of order and contiguous placement for the digits though.
    If it doesn't really have English alphabet in contiguous manner, then how would it work? Take the program above to check if the letter is uppercase or lowercase. In my humble opinion (which I know could be grossly wrong) it won't work. The if-condition condition worked because because ASCII has the values of "A" to "Z" in a sequence (decimal values: from 65 to 90).


    Quote Originally Posted by laserlight View Post
    Turn up your compiler warning level and attempt to compile some code like that. Then, if the compiler does not react as you expect, ask us why.
    The warning for
    Code:
    cout << '++' << endl;
    is: [Warning] multi-character character constant.

    But it still runs and gives value of "11051". What's that?

    By the way, what does it mean when a compiler gives warning(s)?

    The error for
    Code:
    cout << ++ << endl;
    is: expected primary-expression before '<<' token.

    Why is so? Could you please tell?

    Quote Originally Posted by laserlight View Post
    Then you do something depending on what you are trying to do.

    Hint: "what if" questions are nice for you to think out loud, but they require the reader to guess what your thoughts are if you don't actually think out loud your entire train of thoughts. Imagine going to a shop to buy a drink, and you ask the storekeeper "what if I bought this can of coke?" The storekeeper would have to figure out if he should say "then you have to pay me $1" or if he should say "then you would be missing out on this beer" (i.e., he has to figure out whether you are really asking how much it costs, or if you are asking his opinion on what drink to buy).
    Okay, I understand your point. Now I'm trying to think loud. I want to use the character for the constant PI in a console program. I have its ASCII code which is 227. How do I do it.

    Code:
    Area = 2*PI*R;
    Is it any clear or louder now?!

    Quote Originally Posted by laserlight View Post
    The term "sub-function" does not exist in standard C++, so you should explain what you understand by that term.
    By sub-function I meant function within a function. "int main()" is the main function and its body contain the function "system()" as I was saying in my previous post.

    Now please help me with the queries. Thank you for your help.

    ----------------

    Hi Elysia

    Quote Originally Posted by Elysia View Post
    Please x 20 do NOT rely on ASCII. Don't mention it. Don't assume it is used. Don't even think about it.
    The C++ standard does not guarantee what the "underlying character set" is. It could be ASCII, but it could also be something entirely different.
    Furthermore, ASCII is an old american-only system. It needs to go away. Unicode is the new future as it is now.
    So again, don't assume ASCII, and throw away your ASCII table.
    Who/What is that "x 20"? Would you please tell me? Is it me?

    If it is really me, then I won't mention it and throw it away just after using it a few times and along the way would try to learn Unicode. Happy!

    Thank you all of you for guiding me on this stuff. You guys are really helpful.

    Best wishes
    Jackson
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,010
    Quote Originally Posted by jackson6612 View Post
    If it doesn't really have English alphabet in contiguous manner, then how would it work? Take the program above to check if the letter is uppercase or lowercase. In my humble opinion (which I know could be grossly wrong) it won't work. The if-condition condition worked because because ASCII has the values of "A" to "Z" in a sequence (decimal values: from 65 to 90).
    It works for ASCII, because the letters are contiguous. But all character sets are not guaranteed to be contiguous. Thus, the if statement may fail on some platforms.

    The warning for
    Code:
    cout << '++' << endl;
    is: [Warning] multi-character character constant.

    But it still runs and gives value of "11051". What's that?
    Single quotes detonate a single character. Yet, you are putting two characters inside the quotes. Hence, the compiler warns. The exact behavior is either implemented defined or undefined.

    By the way, what does it mean when a compiler gives warning(s)?
    It means you did something you shouldn't, or that you are doing something iffy. Basically, the compiler says "What's this? Is this really right?" and informs you that it's doubtful. Most of the cases, you did something bad.

    The error for
    Code:
    cout << ++ << endl;
    is: expected primary-expression before '<<' token.

    Why is so? Could you please tell?
    Because it's invalid syntax. ++ is an operator and must be applied to some variable. Strings always require double quotes.

    Who/What is that "x 20"? Would you please tell me? Is it me?
    x 20 was just meant to mean "repeat 20 times."

    If it is really me, then I won't mention it and throw it away just after using it a few times and along the way would try to learn Unicode. Happy!
    Good luck and try to keep a lot of sanity stored in reserve. Internationalization today is a pain.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    Quote Originally Posted by jackson6612 View Post
    But this also begs another question. What if I know the ASCII code of some character but don't have a key for that character on the keyboard, let's say PI which has ASCII decimal code of 227?
    You can do:

    Code:
    static_cast<unsigned char>(227)
    Although I think you may run into problems with unsigned chars (char is signed, with values -128 to 127, so static_cast<char>(227) would overflow), somebody else who knows more about character encoding may have to weigh in.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    Quote Originally Posted by jackson6612
    I want to use the character for the constant PI in a console program. I have its ASCII code which is 227. How do I do it.
    It looks like you want to use the value of pi in your program, so you could approximate it with:
    Code:
    const double PI = 3.141593;
    then use PI as in your statement.

    Quote Originally Posted by jackson6612
    By sub-function I meant function within a function. "int main()" is the main function and its body contain the function "system()" as I was saying in my previous post.
    Then no. Standard C++ does not allow for sub-functions. The use of system in main is a function call.

    Quote Originally Posted by jackson6612
    If it is really me, then I won't mention it and throw it away just after using it a few times and along the way would try to learn Unicode.
    Actually, ASCII is a subset of Unicode.

    Quote Originally Posted by Mozza314
    Although I think you may run into problems with unsigned chars (char is signed, with values -128 to 127, so static_cast<char>(227) would overflow),
    You definitely will not run into problems with unsigned chars with such a cast because 227 is within the guaranteed range of unsigned char. Whether char is signed or unsigned is implementation defined.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,010
    Quote Originally Posted by laserlight View Post
    Actually, ASCII is a subset of Unicode.
    Just a little addition to that:
    ASCII is defined for 0-127 (ie 7 bits). The rest (128-255) are various extensions to ASCII that varies with code page. They are not the same in Unicode.
    The first 127 characters (ie the standardized ASCII charset) is also the same in Unicode for backwards compatibility AFAIK.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Elysia View Post
    Just a little addition to that:
    ASCII is defined for 0-127 (ie 7 bits). The rest (128-255) are various extensions to ASCII that varies with code page. They are not the same in Unicode.
    The first 127 characters (ie the standardized ASCII charset) is also the same in Unicode for backwards compatibility AFAIK.
    Unicode Standard

    It's probably more accurate to say that Unicode is a (terrible) rethink of text encoding. For the most part it is unrelated to ASCII, and is not required to contain ASCII characters at all.

  8. #23
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,407
    It's probably more accurate to say that Unicode is a (terrible) rethink of text encoding.
    It isn't a rethink of text encoding at all. It covers several text encodings; it is also much else besides.

    The "Bidirectional Algorithm", for example, while only an annex, is still part of the standard.

    For the most part it is unrelated to ASCII, and is not required to contain ASCII characters at all.
    Yes; It absolutely does. That was part of the design goals of backwards compatibility with most existing protocols.

    It just isn't compatible with "DOS-437" or "Windows-1252" that you probably know of as ASCII being a Windows guy.

    Soma
    Last edited by phantomotap; 04-04-2011 at 10:38 AM. Reason: none of your business

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    Quote Originally Posted by CommonTater
    For the most part it is unrelated to ASCII, and is not required to contain ASCII characters at all.
    From your own link: "The character sets of many existing international, national and corporate standards are incorporated within the Unicode Standard. For example, its first 256 characters are taken from the widely used Latin-1 character set." Consider that Latin-1 is one of those character sets based on ASCII.

    Also: C0 Controls and Basic Latin (Range: 0000-007F)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

Similar Threads

  1. Stuck making part of my code work for testing input
    By KevinP in forum C Programming
    Replies: 6
    Last Post: 01-25-2011, 08:52 AM
  2. Need help getting program print out the digit in words
    By cosmiccomputing in forum C Programming
    Replies: 26
    Last Post: 04-24-2008, 09:28 AM
  3. Replies: 7
    Last Post: 01-01-2008, 12:30 PM
  4. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-26-2001, 12:45 AM
  5. number to a character
    By steven in forum C Programming
    Replies: 2
    Last Post: 09-06-2001, 03:45 PM

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