-5

Could we do something like this?

char word = "violet";

if ("vi" in word)
{
  (do something);
}

Or is there any other way to do it?

Kais3r
  • 21
  • 4
  • 6
    Does this answer your question? [Check substring exists in a string in C](https://stackoverflow.com/questions/12784766/check-substring-exists-in-a-string-in-c) – Turamarth Oct 15 '20 at 14:40
  • 1
    I suspect that the string handling chapter of a C programming book may reveal the answer. Just as the array chapter before it revealed that strings are character arrays `char word[] = ...`. – Lundin Oct 15 '20 at 14:43
  • 1
    Why is this closed as a duplicate of a question asking about finding a *single* character when OP is looking for a longer substring? – Shawn Oct 15 '20 at 15:33

1 Answers1

0

Not quite, but you could write

if (strstr("violet", "vi")){
    // do something
}
Bathsheba
  • 231,907
  • 34
  • 361
  • 483