For example, to validate the valid Url, I\'d like to do the following
char usUrl[MAX] = \"http://www.stackoverflow\"
if(usUrl[0] == \'h\'
&& usUr
A solution using an explicit loop:
#include
#include
#include
bool startsWith(const char *haystack, const char *needle) {
for (size_t i = 0; needle[i] != '\0'; i++) {
if (haystack[i] != needle[i]) {
return false;
}
}
return true;
}
int main() {
printf("%d\n", startsWith("foobar", "foo")); // 1, true
printf("%d\n", startsWith("foobar", "bar")); // 0, false
}