from small one page howto to huge articles all in one place

search text in:




Other .linuxhowtos.org sites:gentoo.linuxhowtos.org



Last additions:
using iotop to find disk usage hogs

using iotop to find disk usage hogs

words:

887

views:

215050

userrating:


May 25th. 2007:
Words

486

Views

261715

why adblockers are bad


Workaround and fixes for the current Core Dump Handling vulnerability affected kernels

Workaround and fixes for the current Core Dump Handling vulnerability affected kernels

words:

161

views:

153931

userrating:


April, 26th. 2006:

Druckversion
You are here: manpages





strncmp

Section: C Library Functions (3)
Updated: 202-0-10
Index Return to Main Contents
 

NAME

strncmp - nonstrings compare  

LIBRARY

Standard C library (libc,~-lc)  

SYNOPSIS

#include~<string.h>  // see memory.h(3head)
int strncmp(const char s1[], const char s2[], size_t n);
 

DESCRIPTION

The strncmp() function is similar to strcmp(3), except it compares only the first (at most) n bytes of s1 and s2. It is equivalent to memcmp(s1, s2, MIN(MIN(strnlen(s1,n),strnlen(s2,n))+1, n))  

RETURN VALUE

See memcmp(3).  

ATTRIBUTES

For an explanation of the terms used in this section, see attributes(7).
InterfaceAttributeValue
strncmp() Thread safetyM-Safe
 

STANDARDS

C11, POSIX.-2008.  

HISTORY

POSIX.-2001, C89, SVr4, 4.3BSD.  

EXAMPLES

The program below can be used to demonstrate the operation of strncmp(). $ ./strncmp ABC AB 3; <strn1> is greater than <strn2> (67) $ ./strncmp ABC AB 2; <strn1> and <str2> are equal in the first 2 bytes  

Program source

// strncmp.c // Licensed under GNU General Public License v2 or later. #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) {
    int res;
    if (argc != 4) {
        fprintf(stderr, "Usage: %s <strn1> <strn2> <n>[rs]n", argv[0]);
        exit(EXIT_FAILURE);
    }
    res = strncmp(argv[1], argv[2], atoi(argv[3]));
    if (res == 0) {
        printf("<strn1> and <strn2> are equal");
        printf(" in the first %d bytes[rs]n", atoi(argv[3]));
        printf("[rs]n");
    } else if (res < 0) {
        printf("<strn1> is less than <strn2> (%d)[rs]n", res);
    } else {
        printf("<strn1> is greater than <strn2> (%d)[rs]n", res);
    }
    exit(EXIT_SUCCESS); }  

SEE ALSO

memory.h(3head), memcmp(3), strncasecmp(3), wcsncmp(3)


 

Index

NAME
LIBRARY
SYNOPSIS
DESCRIPTION
RETURN VALUE
ATTRIBUTES
STANDARDS
HISTORY
EXAMPLES
Program source
SEE ALSO





Support us on Content Nation
rdf newsfeed | rss newsfeed | Atom newsfeed
- Powered by LeopardCMS - Running on Gentoo -
Copyright 2004-2025 Sascha Nitsch Unternehmensberatung GmbH
Valid XHTML1.1 : Valid CSS
- Level Triple-A Conformance to Web Content Accessibility Guidelines 1.0 -
- Copyright and legal notices -
Time to create this page: 14.3 ms