-1

What function should I use if I need to perform an action when a certain word is NOT found AT THE START of a string? Let's say I want to perform an action if the string does not start with "The". So if:

char *str = "This is a string";

the code will perform the action. But if:

char *str = "The quick brown fox jumps over the lazy dog.";

the action will not happen.

NOTE: Case of the letters matter. The word to be compared in the string may not be separated by a space. Also, if it would affect the code in anyway, what if I need to compare the string with 2 different words?

Rex
  • 17
  • 3

1 Answers1

0
if (strncmp(str, "The", strlen("The")) 
{    
/* do some action */ 
}
else 
{
/* don't do anything */ 
}

This should do it?

Also, this is almost a duplicate of How to check if a string starts with another string in C? as pointed out by Jake Wilson

Community
  • 1
  • 1
amrith
  • 953
  • 6
  • 17