Difference between revisions of "Manual:DIL Manual/strcmp()"
Jump to navigation
Jump to search
(XML import) |
(corrected from the DIL keyword tests (T029-T043)) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| + | = strcmp() = | ||
| + | '''Function''' (integer). Compares two strings, minding upper and lower case. | ||
| + | strcmp(s1 : string, s2 : string) | ||
| − | < | + | DIL's <code>==</code> and <code>!=</code> on strings ignore case (<code>"Sofa" == "sofa"</code> is |
| + | true). Use strcmp() when case matters, as with passwords: it compares the two strings byte by | ||
| + | byte, as the C function of that name does. | ||
| − | + | == Parameters == | |
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | s1 || string || The first string. | ||
| + | |- | ||
| + | | s2 || string || The second string. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | Integer: 0 when the strings are the same, less than 0 when <code>s1</code> sorts before | |
| − | + | <code>s2</code>, more than 0 when after. Test the sign only: the value need not be -1 or 1. | |
| − | |||
| − | + | A string variable that was never set counts as <code>""</code>. It fails when an argument is a | |
| − | + | failed value. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| + | == Notes == | ||
| + | * Capitals sort before small letters: <code>strcmp("Z", "a")</code> is less than 0. | ||
| + | * All of DIL's string comparisons ignore case: <code>==</code>, <code>!=</code>, <code><</code>, <code>></code>, <code><=</code> and <code>>=</code>. Only strcmp() and strncmp() mind it. | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin integer same_pwd(first : string, second : string); | |
| − | + | code | |
| − | + | { | |
| − | + | return (strcmp(first, second) == 0); | |
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Tells whether a password was typed the same way twice, capitals included, as the password | ||
| + | change in commands.zon checks with <code>excmdstr_case</code>. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/strncmp()|strncmp()]] | |
| − | + | * [[Manual:DIL Manual/excmdstr case|excmdstr_case]] | |
| − | + | * [[Manual:DIL Manual/tolower()|tolower()]] | |
| − | + | * [[Manual:DIL Manual/Operators|Operators]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 07:21, 15 November 2026
strcmp()
Function (integer). Compares two strings, minding upper and lower case.
strcmp(s1 : string, s2 : string)
DIL's == and != on strings ignore case ("Sofa" == "sofa" is
true). Use strcmp() when case matters, as with passwords: it compares the two strings byte by
byte, as the C function of that name does.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s1 | string | The first string. |
| s2 | string | The second string. |
Returns
Integer: 0 when the strings are the same, less than 0 when s1 sorts before
s2, more than 0 when after. Test the sign only: the value need not be -1 or 1.
A string variable that was never set counts as "". It fails when an argument is a
failed value.
Notes
- Capitals sort before small letters:
strcmp("Z", "a")is less than 0. - All of DIL's string comparisons ignore case:
==,!=,<,>,<=and>=. Only strcmp() and strncmp() mind it.
Example
dilbegin integer same_pwd(first : string, second : string);
code
{
return (strcmp(first, second) == 0);
}
dilend
Tells whether a password was typed the same way twice, capitals included, as the password
change in commands.zon checks with excmdstr_case.