by the way, the answer to your question is:
103 = G lowercase, so 78 must be N uppercase, while 35 is the # sign.
This is a discussion on Checking if a character is a '\' within the C Programming forums, part of the General Programming Boards category; by the way, the answer to your question is: 103 = G lowercase, so 78 must be N uppercase, while ...
by the way, the answer to your question is:
103 = G lowercase, so 78 must be N uppercase, while 35 is the # sign.
You can use the following way also.
Code:#include<stdio.h> main() { int c; while ( (c=getchar())!= '\n' ) { printf("%d\n",c); if ( c == 92 ) /*ascii value of 92 is \*/ { printf("Given character is a backslash\n"); } else { printf("This is not backslash\n"); } } }
By the gods! You were just told why it's bad to use ASCII numbers, and still you try to enforce your bad methods onto newbies? Think!
It's not even guaranteed that your specific platform will use ASCII! Therefore, using character literals is portable, while using ASCII (aka magic numbers) is not!
So use character literals!
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
You are basically saying that the use of magic numbers is good practice if the programmer likes to use them. Despite your attempts at denial, the truth is that magic numbers are not as easy to interpret as named constants and escape sequences. This "to each his own" argument for such an obvious case of good style versus bad style can only hold if no one ever reads anyone else's code.Originally Posted by UltraKing227
There might also be the issue of portability since in theory ASCII is not required, but in practice these days an ASCII based character set will almost definitely be used.
The answer is besides the point. How long did you take to get the answer? If it is anything short of immediate, you're too slow. Did you spot the intentional mistake in my code snippet? How long did you take to notice it? If you needed more than a glance to notice the mistake and its correction, then you're not good enough to use those magic numbers.Originally Posted by UltraKing227
Yet, even if you are good enough, that's not good enough. Everyone who might have to maintain your code has to be good enough.
You might want to at least skim through the existing replies before you make your own. Adak already gave such a suggestion in the very first reply to the topic, and thus the current question of a hard coded value versus using an escape sequence.Originally Posted by thillai_selvan
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