c-md/srcs/utils/string/starts_with.c.md
2026-01-12 16:22:13 +01:00

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 of str.

Return Value

  • Returns 1 (true) if str starts with prefix.
  • 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));
}