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

Detailed Description

Contains string str_inn 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_inn.c.

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

Go to the source code of this file.

Functions

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.
 

Function Documentation

◆ str_inn()

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.

This function scans the string s to find the substring t. It only considers the first n characters of s. If t is found within these bounds, a pointer to the beginning of t in s is returned.

Parameters
sThe string to be searched.
tThe substring to locate within s.
nThe maximum number of characters in s to be searched.
Returns
A pointer to the first occurrence of t in s, or NULL if t is not found within the first n characters.

Definition at line 30 of file str_inn.c.

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}