memcmp : memcmp « string.h « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C / ANSI-C
C++
C++ Tutorial
Visual C++ .NET
C Tutorial » string.h » memcmp 
24.2.1.memcmp
ItemValue
Header filestring.h
Declarationint memcmp(const void *buf1, const void *buf2, size_t count);
Functioncompares the first count characters between buf1 and buf2.
Returnreturns an integer as follows:


ValueMeaning
< 0buf1 is less than buf2
0buf1 is equal to buf2
> 0buf1 is greater than buf2


#include <stdio.h>
  #include <string.h>
  #include <stdlib.h>

  int main(int argc, char *argv[])
  {
    int outcome, len, l1, l2;

    char *str = "asdf";
    char *str1 = "asdfasdf";

    /* find the length of shortest string */
    l1 = strlen(str);
    l2 = strlen(str1);
    len = l1 < l2 ? l1:l2;

    outcome = memcmp(str, str1, len);

    if(!outcome)
        printf("Equal");
    else if(outcome<0)
        printf("First less than second.");
    else
        printf("First greater than second.");

    return 0;
  }
Equal
24.2.memcmp
24.2.1.memcmp
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.