-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstristr.c
executable file
·38 lines (29 loc) · 873 Bytes
/
stristr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// from http://c.snippets.org/code/stristr.c without the usage of NUL and NULL
#ifndef STRISTR
#define STRISTR
#include <ctype.h>
//static
char *stristr(const char *String, const char *Pattern)
{
char *pptr, *sptr, *start;
for (start = (char *)String; *start; start++)
{
/* find start of pattern in string */
for ( ; (*start && (toupper(*start) != toupper(*Pattern))); start++)
;
if (!*start)
return 0;
pptr = (char *)Pattern;
sptr = (char *)start;
while (toupper(*sptr) == toupper(*pptr))
{
sptr++;
pptr++;
/* if end of pattern then pattern was found */
if (!*pptr)
return (start);
}
}
return 0;
}
#endif