Created
November 7, 2014 02:54
-
-
Save zaltoprofen/76a243277abe23f1c4ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <assert.h> | |
int start_with(char const *str, char const *prefix){ | |
if (strlen(str) < strlen(prefix)) | |
return 0; | |
return strstr(str, prefix) == str; | |
} | |
int main(int argc, char const* argv[]) | |
{ | |
assert(start_with("abcdefg", "abc")); | |
assert(!start_with("abcdefg", "123")); | |
assert(!start_with("abc", "abcdefg")); | |
assert(!start_with("123", "abcdefg")); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment