667 B
667 B
starts_with.c
Checks if a string starts with a given prefix.
Includes
#include <string.h>
#include <stdint.h>
#include "utils.h"
Function Description
starts_with
Checks if the string str starts with the substring prefix.
Parameters
str: The main string to check.prefix: The prefix to look for at the start ofstr.
Return Value
- Returns
1(true) ifstrstarts withprefix. - Returns
0(false) otherwise.
Implementation
int8_t
starts_with(const char *str, const char *prefix)
{
size_t prefix_len;
prefix_len = strlen(prefix);
return (0 == strncmp(str, prefix, prefix_len));
}