Author: enrico-sorichetti
Subject: Reply to: Wildcard logic in COBOL
Posted: Thu Sep 01, 2016 9:16 pm (GMT 5.5)
the logic is the logic, DOES NOT DEPEND on the programming language
here is a sample in C
_________________
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort![icon_cool.gif]()
Subject: Reply to: Wildcard logic in COBOL
Posted: Thu Sep 01, 2016 9:16 pm (GMT 5.5)
the logic is the logic, DOES NOT DEPEND on the programming language
here is a sample in C
Code: |
/* a ? matches a single char a * matches 0 more than 0 chars */ #include "stdlib.h" #include "stdio.h" int wc(const char *mask, const char *string) { const char *cp = NULL, *mp = NULL; while ((*string) && (*mask != '*')) { if ((*mask != *string) && (*mask != '?')) { return 0; } mask++; string++; } while (*string) { if (*mask == '*') { if (!*++mask) { return 1; } mp = mask; cp = string+1; } else if ((*mask == *string) || (*mask == '?')) { mask++; string++; } else { mask = mp; string = cp++; } } while (*mask == '*') { mask++; } return !*mask; } |
_________________
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
