SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
str_in.c File Reference

Detailed Description

Implementation of the str_in function.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file str_in.c.

#include "mdb.h"
#include <ctype.h>

Go to the source code of this file.

Functions

char * str_in (char *s, char *t)
 Finds the first occurrence of the substring t in the string s.
 

Function Documentation

◆ str_in()

char * str_in ( char * s,
char * t )

Finds the first occurrence of the substring t in the string s.

This function searches for the substring t within the string s and returns a pointer to the first occurrence of t. If t is not found, the function returns NULL.

Parameters
sThe string to be searched.
tThe substring to search for within s.
Returns
A pointer to the first occurrence of t in s, or NULL if t is not found.

Definition at line 29 of file str_in.c.

29 {
30 register char *ps0, *pt, *ps;
31
32 if (s == NULL || t == NULL)
33 return (NULL);
34
35 ps0 = s;
36 while (*ps0) {
37 if (*t == *ps0) {
38 ps = ps0 + 1;
39 pt = t + 1;
40 while (*pt && *ps == *pt) {
41 pt++;
42 ps++;
43 }
44 if (*pt == 0)
45 return (ps0);
46 }
47 ps0++;
48 }
49 return (NULL);
50}