declaring ranges a-z A-Z 0-9 etc. ?

This is a discussion on declaring ranges a-z A-Z 0-9 etc. ? within the C Programming forums, part of the General Programming Boards category; Is there a way to declare ranges for conditional testing, like [A-Z] or [0-9] ? Basically I want to turn ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    declaring ranges a-z A-Z 0-9 etc. ?

    Is there a way to declare ranges for conditional testing, like [A-Z] or [0-9] ?

    Basically I want to turn any char that is not a letter into a space by saying something like:
    Code:
    if ( c != [A-Z] || c != [a-z]) { c = ' '} return c;
    instead of (mostly b/c I get the warning that char constant is too long for its type):
    Code:
    int replacenum ( int c) { 
      if ( c=='1'||c=='2'||c=='3')||c=='4'||c=='5'||c=='6'||c=='7'||
           c=='8'||c=='9'||c=='0'||c=='`'||c=='~'||c=='!'||c=='@'||
           c=='#'||c=='$'||c=='%'||c=='^'||c=='&'||c=='*'||c=='('||
           c==')'||c=='-'||c=='_'||c=='+'||c=='='||c=='{'||c=='['||
           c=='}'||c==']'||c=='|'||c=='\')//||c==':'||c==';'|| ... )
       {
         c = ' ';
       }
       return c;
    }

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Have a look in <ctype.h>. You should be able to find some useful functions in there that will make what you are trying to do a lot simpler. In particular, you can use isgraph() and isalpha() to get what you want.
    Last edited by kermit; 07-01-2010 at 07:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Manual calculation of variable type ranges
    By Kayl669 in forum C Programming
    Replies: 10
    Last Post: 02-27-2010, 12:25 PM
  2. problem in declaring dyanamic arrays in c
    By aqeel in forum C Programming
    Replies: 2
    Last Post: 09-23-2009, 01:10 AM
  3. SQL Exception ( declaring a variable )
    By Aga^^ in forum C# Programming
    Replies: 3
    Last Post: 07-21-2009, 04:49 AM
  4. different ways of declaring classes
    By confuted in forum C++ Programming
    Replies: 7
    Last Post: 08-19-2003, 09:35 AM
  5. Declaring Functions
    By Thantos in forum C Programming
    Replies: 3
    Last Post: 09-25-2001, 11:24 PM

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