> For the complete documentation index, see [llms.txt](https://docs.hyperdbg.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hyperdbg.org/commands/scripting-language/functions/strings/strncmp.md).

# strncmp

### Function

> strncmp

### Syntax

> strncmp( Str1, Str2, Num );

### Parameters

**\[Str1]**

A [MASM-like expression](https://docs.hyperdbg.org/commands/scripting-language/assumptions-and-evaluations) or a string to compare with **Str2**.

**\[Str2]**

A [MASM-like expression](https://docs.hyperdbg.org/commands/scripting-language/assumptions-and-evaluations) or a string to compare with **Str1**.

**\[Num]**

Maximum number of characters to compare.

### Description

Compares up to ***Num*** characters of the string ***Str1*** to the string ***Str2***.

If the characters are equal, the comparison continues with the next pair of characters. This process repeats until the characters differ, a terminating null character is encountered, or ***Num*** characters have been compared in both strings, whichever occurs first.

### Return value

Returns an integer value indicating the relationship between the strings:<br>

| Return Value | Indicates                                                                                     |
| ------------ | --------------------------------------------------------------------------------------------- |
| <0           | The first character that does not match has a lower value in ***Str1*** than in ***Str2**.*   |
| 0            | The contents of both strings are equal.                                                       |
| >0           | The first character that does not match has a greater value in ***Str1*** than in ***Str2**.* |

### Examples

``strncmp(fffff806`6de00000, @rax+c0, 0n12);``

Compare the first 12 (decimal) characters of the string located at ``fffff806`6de00000`` with the string located at `@rax+c0`.

`strncmp(@rcx, "Test String", b);`

Compare the first 0xb (hexadecimal) characters of the string located at `@rcx` with the string `"Test String"`.

`strncmp("Test String1", "Test String2", 0n7);`

Compare the first 7 (decimal) characters of the string `"Test String1"` with the string `"Test String2"`.

### Remarks

This function checks for the validity of both the source and the destination address before the comparison.

The support for this function is added from **v0.9**.

### Related

[wcscmp](https://docs.hyperdbg.org/commands/scripting-language/functions/strings/wcscmp)

[wcsncmp](https://docs.hyperdbg.org/commands/scripting-language/functions/strings/wcsncmp)

[memcmp](https://docs.hyperdbg.org/commands/scripting-language/functions/memory/memcmp)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hyperdbg.org/commands/scripting-language/functions/strings/strncmp.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
