40 lines
667 B
Markdown
40 lines
667 B
Markdown
# starts_with.c
|
|
|
|
Checks if a string starts with a given prefix.
|
|
|
|
---
|
|
|
|
## Includes
|
|
```c
|
|
#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
|
|
```c
|
|
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));
|
|
}
|
|
```
|