Thread: text comparing

  1. #46
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    Maybe I didn't understand something but I thought you said that quzahs didn't recognise between numbers and letters. If I understand his code, it is based on the spaces. But I can't use spaces to recognise because when I get the plate it could have mistakes in the spaces and sais that there is a space where there isn't.

    For example, it sais that the plate in the picture is 111 1 AAA, so we have one space more than in the pattern that is 1111 AAA, so I can't use the spaces for recognison.

    What a do is : I get 111 1 AAA, I make it become 1111AAA and compare it with the pattern that is in this case 1111AAA (whithout spaces).

    Maybe I'm explainig something that you already undesrtand, but I re-appologise for my very very bad english, so maybe I'm confused.
    Last edited by Picachu; 12-13-2006 at 11:24 AM.

  2. #47
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Same code, minor change to skip spaces. Same end result:
    Code:
    #include<stdio.h>
    #include<ctype.h>
    int parse( char *s )
    {
        if( s )
        {
            int a = 0, b = 0, c = 0, num = 0;
            while( *s && (isalpha( *s ) || ' ' == *s) ) a += (' '!=*s++);
            while( *s && (isdigit( *s ) || ' ' == *s) ) b += (' '!=*s++);
            while( *s && (isalpha( *s ) || ' ' == *s) ) c += (' '!=*s++);
            
            num = (a * 100) + (b * 10) + c;        
    
            switch( num )
            {
                case  43: /*    1111  AAA */ case 141: /*  A 1111  A */
                case 142: /*  A 1111  AA  */ case 241: /* AA 1111  A */
                case 242: /* AA 1111  AA  */ case 150: /*  A 11111   */
                case 250: /* AA 11111     */ return 1;       
                default: return 0;
            }
        }
        return 0;
    }
    
    int main( void )
    {
        char *tests[] =
        {
            "911aB", "AAA 564", "6114 DFa", "1111Aaa", "aa 11", "GF 1511 SS",
            "aa111aa", "aa111a", "aa111aaa", "XX 11111", "a@ 11311", "a 4511",
            "a1111"
        };
        size_t x;
        
        for( x = 0; x < sizeof tests / sizeof tests[0]; x++ )
        {
            printf("parse( %s ) == %d\n", tests[x], parse( tests[x] ) );
        }
        
        return 0;
    }
    
    /*
    parse( 911aB ) == 0
    parse( AAA 564 ) == 0
    parse( 6114 DFa ) == 1
    parse( 1111Aaa ) == 1
    parse( aa 11 ) == 0
    parse( GF 1511 SS ) == 1
    parse( aa111aa ) == 0
    parse( aa111a ) == 0
    parse( aa111aaa ) == 0
    parse( XX 11111 ) == 1
    parse( a@ 11311 ) == 0
    parse( a 4511 ) == 0
    parse( a1111 ) == 0
    */
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #48
    Registered User
    Join Date
    Dec 2006
    Posts
    22
    Ok now I understand. Thank you very much, I like it a lot.

    I hope my boss will like it to. ;-)

    Thanks a lot.

  4. #49
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Have them send me a check.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Scrolling The Text
    By GaPe in forum C Programming
    Replies: 3
    Last Post: 07-14-2002, 04:33 PM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM