pattern matching help 
Author Message
 pattern matching help

I need to write a program that will read first a pattern and
then a long string of characters in which the pattern will
be included. The program needs to output the number of times
the pattern occurs throughout the string of character.

Ex:
hello \*this is the pattern to be matched*\
knklsdfhellojkdlop
sdfjklhellojjklhello

OUTPUT:3  \*hello appears three times within those two lines
           of characters*\

The program must be case-insensitive as well.  Any help anyone
can give will be most helpful.  You can email me at the address



Sun, 10 May 1998 03:00:00 GMT  
 pattern matching help

: The program must be case-insensitive as well.  Any help anyone
: can give will be most helpful.  You can email me at the address

#include <stdio.h>
#include <string.h>
main()
{
   char buf[] = "aljsdfahelloal;djfadfhelloasld;fkjahello";
   char *ptr_1, *ptr_2;
   int i = 0;
   ptr_1 = buf;
   while(ptr_2 = strstr(ptr_1, "hello")) {
      i++;
      ptr_2 += strlen("hello");
      ptr_1 = ptr_2;
   }
   printf("There are %d matching patterns.\n", i);

Quote:
}

--
"The most incomprehensible thing about the world is that it is
at all comprehensible."
                -- Albert Einstein (1879-1955)
---
SigGenre 0.1k (.signature and .plan generator)

ftp://ftp.clark.net/pub/times9   http://www.clark.net/pub/times9


Mon, 11 May 1998 03:00:00 GMT  
 pattern matching help

Quote:
>I need to write a program that will read first a pattern and
>then a long string of characters in which the pattern will
>be included. The program needs to output the number of times
>the pattern occurs throughout the string of character.

If you are using a system containing grep or something like
this, you may extract the pattern from the first line and than
call grep in the apropriate way.

However this becomes systemspecific.

Hans Friedrich Steffani
--
Hans Friedrich Steffani
Institut fuer Elektrische Maschinen und Antriebe
TU Chemnitz-Zwickau



Mon, 11 May 1998 03:00:00 GMT  
 pattern matching help

: I need to write a program that will read first a pattern and
: then a long string of characters in which the pattern will
: be included. The program needs to output the number of times
: the pattern occurs throughout the string of character.

: Ex:
: hello \*this is the pattern to be matched*\
: knklsdfhellojkdlop
: sdfjklhellojjklhello

: OUTPUT:3  \*hello appears three times within those two lines
:          of characters*\

Actually, the pattern occured four times in that example.  The word
occured three times.  

: The program must be case-insensitive as well.  Any help anyone
: can give will be most helpful.  You can email me at the address

If you haven't recieved any help in a couple of days, email me and I
think I should be able to help.
--
     _______    ______    _______

    |  |_|  |  |   _  |  |  |_|  |
    |   _  |   |  |_| |  |   _  |    ** the fingers that put the
    |  |_|  |  |      |  |  |_|  |          ice in your drinks
    |_______|  |______|  |_______|          clean the urinals!



Wed, 13 May 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Regular Expressions/Pattern Matching/Unordered pattern

2. Help, Pattern used in Regex.Matches(...)

3. help with a fast pattern matching utility requested

4. Help with Pattern Matching!

5. Pattern matching NEED HELP

6. Help on string pattern matching?

7. Pattern Matching in VC++ Help...

8. Pattern Matching in C -

9. Pattern Matching Tool

10. Pattern Matching in C

11. pattern matching and string replacement

12. Pattern Matching in execution time

 

 
Powered by phpBB® Forum Software