Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>strncmp() compare n characters of two strings, case sensitive</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 strncmp()               Compare n Characters of Two Strings, Case Sensitive

 #include   <string.h>                   Required for declarations only

 int           strncmp(string1,string2,n);
 const char    *string1;
 const char    *string2;
 size_t        n;                        Number of characters to compare

    strncmp() compares up to 'n' characters of 'string1' and 'string2'.
    The strings are compared lexicographically, and case is significant
    (i.e., 'A' != 'a').

       Returns:     A value indicating the relationship between the two
                    strings:

                          Comparison          Returned

                    'string1' <  'string2'      < 0
                    'string1' == 'string2'        0
                    'string1' >  'string2'      > 0

         Notes:     strncmp() expects to operate on null-terminated
                    strings.  No overflow checking is done when strings
                    are copied or appended.

   -------------------------------- Example ---------------------------------
    The following statements compare 'n' characters of two strings and
    find the strings equivalent.


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

           char str1[20] = "eucalyptus";
           char str2[20] = "eucalyptus Trees";
           int rslt;

           main()
           {
               if((rslt = strncmp(str1,str2,strlen(str1))) == 0)
                   printf("strings are equivalent");
               else
                  printf("strings are not equivalent");
           }


See Also: strcmp() strnicmp()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson