Category : C Source Code
Archive   : CSRC2.ZIP
Filename : MATCH.C

Output of file : MATCH.C contained in archive : CSRC2.ZIP
* m a t c h . c



title match Determine if a String Is a Leading Substring of Another
index Determine if a string matches a leading substring of another
index Pattern matching - match constant string


char *
char *s;
char *p;


match(s,p) returns a pointer to the first character of s beyond those
matching p, if p is an initial substring of s. Otherwise, it returns
NULL. Thus,


returns a pointer to the 'd' in the first string;


returns NULL.



Jerry Leichter


* Edit history
* 0.0 4-May-81 JSL Invention
* 1.0 7-May-81 JSL Now returns pointer to first character after the match
* instead of just TRUE.
* 1.1 23-Jun-81 JSL Conversion to the new documentation conventions.

#define NULL 0

char *
register char *s, *p;
while (*s == *p && *s != '\0') {
* No need to check *p; it equals *s or
* the first test fails.
return((*p != '\0') ? NULL : s);

  3 Responses to “Category : C Source Code
Archive   : CSRC2.ZIP
Filename : MATCH.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: