Is there any method in C
can find a text within another text?
For example, text = "abaHello"
, textneedtoSearch = "Hello";
.
If the text
contains "Hello"
, return true, else return false
.
Use strstr
, see http://pubs.opengroup.org/onlinepubs/9699919799/functions/strstr.html
Character and string searching functions
`char *strstr( const char *s1, const char *s2)`
returns a pointer to the first instance of string s2 in s1. Returns a NULL pointer if s2 is not encountered in s1.
In additon,
int strcmp(const char *s1, const char *s2);
strcmp
compares the string s1 to the string s2. The function returns 0 if they are the same, a number < 0 if s1 < s2, a number > 0 if s1 > s2.This is one of the most commonly used of the string-handling functions.
And check this link for anything about string functions in C, C string functions
if (strstr(text, textneedtoSearch) != NULL)
printf("found\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With