Checking if a character is a '\'

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 ...

  1. #16
    Registered User UltraKing227's Avatar
    Join Date
    Jan 2010
    Location
    USA, New york
    Posts
    123
    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
    Posts
    37
    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");
                    }
            }
    }

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    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
    Location
    Singapore
    Posts
    21,436
    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.
    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. 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

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