From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/string%2Fbyte%2Fstrstr.html | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 devdocs/c/string%2Fbyte%2Fstrstr.html (limited to 'devdocs/c/string%2Fbyte%2Fstrstr.html') diff --git a/devdocs/c/string%2Fbyte%2Fstrstr.html b/devdocs/c/string%2Fbyte%2Fstrstr.html new file mode 100644 index 00000000..0d03ea16 --- /dev/null +++ b/devdocs/c/string%2Fbyte%2Fstrstr.html @@ -0,0 +1,56 @@ +

strstr

Defined in header <string.h>
char *strstr( const char *str, const char *substr );
+
(1)
/*QChar*/ *strstr( /*QChar*/ *str, const char *substr );
+
(2) (since C23)
+1) Finds the first occurrence of the null-terminated byte string pointed to by substr in the null-terminated byte string pointed to by str. The terminating null characters are not compared.
+2) Type-generic function equivalent to (1). Let T be an unqualified character object type. If a macro definition of each of these generic functions is suppressed to access an actual function (e.g. if (strstr) or a function pointer is used), the actual function declaration (1) becomes visible.

The behavior is undefined if either str or substr is not a pointer to a null-terminated byte string.

+

Parameters

+ + +
str - pointer to the null-terminated byte string to examine
substr - pointer to the null-terminated byte string to search for

Return value

Pointer to the first character of the found substring in str, or a null pointer if such substring is not found. If substr points to an empty string, str is returned.

+

Example

#include <string.h>
+#include <stdio.h>
+ 
+void find_str(char const *str, char const *substr)
+{
+    char *pos = strstr(str, substr);
+    pos ? printf("found the string '%s' in '%s' at position %td\n",
+                 substr, str, pos - str)
+        : printf("the string '%s' was not found in '%s'\n",
+                 substr, str);
+}
+ 
+int main(void)
+{
+    char *str = "one two three";
+    find_str(str, "two");
+    find_str(str, "");
+    find_str(str, "nine");
+    find_str(str, "n");
+ 
+    return 0;
+}

Output:

+
found the string 'two' in 'one two three' at position 4
+found the string '' in 'one two three' at position 0
+the string 'nine' was not found in 'one two three'
+found the string 'n' in 'one two three' at position 1

References

See also

+ + +
finds the first occurrence of a character
(function)
finds the last occurrence of a character
(function)
C++ documentation for strstr
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/string/byte/strstr +

+
-- cgit v1.2.3