SDDSlib
Loading...
Searching...
No Matches
str_inn.c
Go to the documentation of this file.
1/**
2 * @file str_inn.c
3 * @brief Contains string str_inn 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 Searches for the first occurrence of substring `t` within the first `n` characters of string `s`.
21 *
22 * This function scans the string `s` to find the substring `t`. It only considers the first `n` characters of `s`.
23 * If `t` is found within these bounds, a pointer to the beginning of `t` in `s` is returned.
24 *
25 * @param s The string to be searched.
26 * @param t The substring to locate within `s`.
27 * @param n The maximum number of characters in `s` to be searched.
28 * @return A pointer to the first occurrence of `t` in `s`, or `NULL` if `t` is not found within the first `n` characters.
29 */
30char *str_inn(s, t, n) char *s, *t;
31long n;
32{
33 register char *ps0, *pt, *ps;
34 register long i;
35
36 if (s == NULL || t == NULL)
37 return (NULL);
38
39 ps0 = s;
40 i = strlen(t);
41 while (*ps0 && n >= i) {
42 i++;
43 if (*t == *ps0) {
44 ps = ps0 + 1;
45 pt = t + 1;
46 while (*pt && *ps == *pt) {
47 pt++;
48 ps++;
49 }
50 if (*pt == 0)
51 return (ps0);
52 }
53 ps0++;
54 }
55 return (NULL);
56}
char * str_inn(char *s, char *t, long n)
Searches for the first occurrence of substring t within the first n characters of string s.
Definition str_inn.c:30