XINU
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
strncmp.c File Reference

二つの文字列を最大N byteまで比較し、その結果を返す。 More...

Go to the source code of this file.

Functions

int strncmp (char *s1, char *s2, int n)
 二つの文字列を最大N byteまで比較し、その結果を返す。 More...
 

Detailed Description

二つの文字列を最大N byteまで比較し、その結果を返す。

Definition in file strncmp.c.

Function Documentation

◆ strncmp()

int strncmp ( char *  s1,
char *  s2,
int  n 
)

二つの文字列を最大N byteまで比較し、その結果を返す。

Parameters
[in]s1比較対象の文字列その1
[in]s2比較対象の文字列その2
[in]n比較するByte数(最大Byte)
Returns
s1 > s2の場合は0より大きい値、s1 = s2の場合は0、s1 < s2の場合は0より小さい値を返す。

Definition at line 13 of file strncmp.c.

14 {
15 
16  while (--n >= 0 && *s1 == *s2++)
17  {
18  if (*s1++ == '\0')
19  {
20  return 0;
21  }
22  }
23  return (n < 0 ? 0 : *s1 - *--s2);
24 }