Thread: Pattern matching

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    Pattern matching

    Code:
    void testformatch(char pattern[],int pat_count,char buffer[],int buf_count)
    {
     
    	while( pattern[pat_count] == buffer[buf_count] )
    	{
    	pat_count++;
    	buf_count++;
    	}
     
    	if(pattern[pat_count]=='\0')
    	{ 
    	printf("match\n");
    	pat_count=0;
    	}
    	else
    	{
    	pat_count=0;
    	}
     
    }
    I am trying to play with a simple algorithm to find a string for some reason Ican't get it to find it if they are exactly the same.

    ie if pattern="ab2";
    and buffer="ab2";
    it won't give me a match.


    Code:
    int main(void){
     
    char buffer[]="abc1";
    char pattern[]="abc1";
    int pat_count=0;
    int buf_count=0;
     
    while( (buffer[buf_count]) != '\0' )
    {
    testformatch(pattern,pat_count,buffer,buf_count);
    buf_count++;
    }
    return 0;
    }
    Last edited by manofsteel972; 10-08-2004 at 06:37 PM. Reason: oops sloppy formatting let me clean that up
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. filename pattern matching
    By dwks in forum C Programming
    Replies: 11
    Last Post: 07-13-2005, 10:23 AM
  3. Pattern matching
    By GSLR in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-06-2003, 07:17 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  5. pattern matching
    By ahahplz in forum C Programming
    Replies: 5
    Last Post: 02-07-2003, 07:15 PM