cant figure it out

This is a discussion on cant figure it out within the C Programming forums, part of the General Programming Boards category; i am trying to allow combinations of 3 numbers eg. 222 or 2 numbers followed by a capital letter eg. ...

  1. #1
    ck1
    ck1 is offline
    Registered User
    Join Date
    Mar 2005
    Posts
    9

    cant figure it out

    i am trying to allow combinations of 3 numbers eg. 222 or 2 numbers followed by a capital letter eg. 21A. It works fine for the 3 numbers but doesnt accept 2 numbers followed by a letter.

    Code:
     if((u_no[0] > 47) && (u_no[0] < 58))
     {
        if((u_no[1] > 47) && (u_no[1] < 58))
        {
           if((u_no[2] > 47) && (u_no[2] < 58))
           {
              u_count_parts++;
              printf("u_no ok\n");
           }
           if((u_no[2] > 64) && (u_no[2] > 91))
           {
              u_count_parts++;
              printf("u_no ok\n");
           }
        }
     }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Code:
    if((u_no[2] > 64) && (u_no[2] > 91))
    There's a problem there...
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    212
    Code:
    //if first position is a number
    if((u_no[0] > 47) && (u_no[0] < 58))
     {
        //if second position is a number
        if((u_no[1] > 47) && (u_no[1] < 58))
        {
            //if first position is a number or a letter
           if((u_no[2] > 47) && (u_no[2] < 58)  || (u_no[2] > 64) && (u_no[2] < 91))
           {
              u_count_parts++;
              printf("u_no ok\n");
           }
        }
     }

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Using isdigit() and isalpha() from <ctype.h> will help.

  5. #5
    ck1
    ck1 is offline
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    is there anything to restrict it to just capitals?

  6. #6
    ck1
    ck1 is offline
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    Quote Originally Posted by ck1
    is there anything to restrict it to just capitals? i have this code now
    Code:
      if((u_no[0] > 47) && (u_no[0] < 58))
       {
          if((u_no[1] > 47) && (u_no[1] < 58))
          {
             if((isalpha(u_no[2])) || (isdigit(u_no[2])))
             {
                u_count_parts++;
                printf("u_no ok\n");
             }
          }
       }

  7. #7
    Registered User
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    212
    Code:
    (u_no[2] > 64) && (u_no[2] < 91)
    From the code i provided above should do it.

    or use isupper() from ctype.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Figure out how method was called?
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2009, 09:43 AM
  2. 3 dimensional figure volume
    By thekautz in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2009, 04:22 PM
  3. trying to figure out someone's code for a plugin
    By paulpars in forum C++ Programming
    Replies: 4
    Last Post: 07-20-2006, 10:57 AM
  4. newb to C, cant figure something out.
    By Phate4219 in forum C Programming
    Replies: 16
    Last Post: 03-06-2006, 12:47 AM
  5. ahh i can't figure out this loop
    By blindleaf in forum C Programming
    Replies: 1
    Last Post: 03-18-2003, 08:42 AM

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