
#include <lcstring.h> int stcpma(char *str, const char *pat);
stcpma tests the input string addressed by str to determine
whether it starts with a substring matching the pattern that pat
points to. The search terminates if a match is not found at the
beginning of the input string.
The pattern format can be specified using the symbols +, *,
and ?, as described in the previous discussion of the stcpm
function.
Although the stcpm and stcpma functions use the same
pattern-matching notation, stcpma is different from stcpm in
two ways:
stcpma looks for a match to the search pattern (pat) only at
the beginning of the input string (str). The stcpm function scans the
entire string for the first match, which may or may not occur at the
beginning.
stcpma does not take a third argument.
stcpma returns the length of the character
sequence that matches the search pattern, or it returns 0 if no match is found.
In comparison to stcpm, both stcpm and stcpma can find the
search pattern William A*.* *Tell in the following input string:
"William A. Tell, Margaret Fairfax-Tell"However,
stcpma cannot find the search pattern in this string:
"Margaret Fairfax-Tell, William A. Tell"And
stcpma cannot find it in this string, which contains an
initial blank:
" William A. Tell"
#include <lcstring.h>
#include <stdio.h>
main()
{
static char *sps[ ] = {
"William Tellas Sr.", /* no middle initial */
"William A Tella ", /* middle initial */
"William AAA. Tell!! ---", /* initial and period */
"William S. Teller; Then..", /* wrong initial */
};
int length, i;
/* Find William Tell, whether or not he used his */
/* middle initial. */
for (i = 0; i < 4; i++) {
if (length = stcpma(sps[i], "William A*.* *Tell"))
printf("%d. Match result = %.*sn", i,length, sps[i]);
else
printf("%d. No match for string = %sn",i,sps[i]);
}
}
stcpm
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.