check if string starts with c 1

check if string starts with c

bool StartsWith(const char *a, const char *b)
{
   if(strncmp(a, b, strlen(b)) == 0) return 1;
   return 0;
}

...

if(StartsWith("http://stackoverflow.com", "http://")) { 
   // do something
}else {
  // do something else
}

Here is what the above code is Doing:
1. It’s checking if the string “http://stackoverflow.com” starts with “http://”
2. If it does, it does something
3. If it doesn’t, it does something else

Similar Posts