Thread: Checking if a character is a '\'

  1. #16
    Registered User UltraKing227's Avatar
    Join Date
    Jan 2010
    USA, New york
    by the way, the answer to your question is:

    103 = G lowercase, so 78 must be N uppercase, while 35 is the # sign.

  2. #17
    Registered User
    Join Date
    Feb 2010
    You can use the following way also.
            int c;
            while ( (c=getchar())!= '\n' )
                    if ( c == 92 ) /*ascii value of 92 is \*/
                            printf("Given character is a backslash\n");
                            printf("This is not backslash\n");

  3. #18
    Join Date
    Oct 2007
    Inside my computer
    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!
    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++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Quote Originally Posted by UltraKing227
    ASCII nums should never be excluded from programming, unless
    the reader is a beginner. everyone has his own methods, i
    like ASCII nums while others may not like using ASCII nums.
    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.

    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.

    Quote Originally Posted by UltraKing227
    by the way, the answer to your question is:
    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.

    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.

    Quote Originally Posted by thillai_selvan
    You can use the following way also.
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  4. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM
  5. Remove character from string
    By nooksooncau in forum C Programming
    Replies: 11
    Last Post: 06-05-2006, 09:37 AM