SDDSlib
Loading...
Searching...
No Matches
str_in.c
Go to the documentation of this file.
1/**
2 * @file str_in.c
3 * @brief Implementation of the str_in function.
4 *
5 * @copyright
6 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
7 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
8 *
9 * @license
10 * This file is distributed under the terms of the Software License Agreement
11 * found in the file LICENSE included with this distribution.
12 *
13 * @author M. Borland, C. Saunders, R. Soliday
14 */
15
16#include "mdb.h"
17#include <ctype.h>
18
19/**
20 * @brief Finds the first occurrence of the substring `t` in the string `s`.
21 *
22 * This function searches for the substring `t` within the string `s` and returns a pointer
23 * to the first occurrence of `t`. If `t` is not found, the function returns `NULL`.
24 *
25 * @param s The string to be searched.
26 * @param t The substring to search for within `s`.
27 * @return A pointer to the first occurrence of `t` in `s`, or `NULL` if `t` is not found.
28 */
29char *str_in(char *s, char *t) {
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}
char * str_in(char *s, char *t)
Finds the first occurrence of the substring t in the string s.
Definition str_in.c:29