Let’s say I have the following content:
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
How do I search for dummy or dummy text in that string using C? Is there any easy way to do it or only with strong string manipulation? All I need is to search for it and return a Boolean with the result.
EDIT:
You guys created a big discussion around this topic and suggested a few algorithms and I don’t mind that cause this might be useful for someone else, or even me in the future. But what I really wanted was the most easy way to do it, no matter the time/space complexity. That doesn’t really matter for what I’m doing. So, strstr easily and quickly fixed my problem. I really have to get me some standard C functions chet sheet.
The standard library function for this is strstr:
It returns a pointer into the string where the match was found, or NULL if it wasn’t – so if all you need is a boolean, just test the return value (
if (strstr(...)).