Thread: what does strcmp return?

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    81

    what does strcmp return?

    Code:
    strcmp(str1,str2);
    strcmp returns always "1" if str1>str2 ?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    From the manual...
    Code:
    RETURN VALUE
           The strcmp() and strncmp() functions return an integer less than, equal
           to, or greater than zero if s1 (or the first n bytes thereof) is found,
           respectively, to be less than, to match, or be greater than s2.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    81
    Quote Originally Posted by EVOEx View Post
    From the manual...
    Code:
    RETURN VALUE
           The strcmp() and strncmp() functions return an integer less than, equal
           to, or greater than zero if s1 (or the first n bytes thereof) is found,
           respectively, to be less than, to match, or be greater than s2.
    thanks...

  4. #4
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Code:
    strcmp("foo", "bar");
    This will return 1 because "foo" is not equal to "bar".

    Code:
    strcmp("foo", "foo");
    This will return 0 because "foo" is equal to "foo". If two strings are not equal, the function may also return -1.
    Last edited by Babkockdood; 06-19-2010 at 05:23 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Babkockdood, the reply above pulled directly from the manual for strcmp explains it all.
    Let str1 and str2 be strings.
    If str1 < str2, return < 0.
    If str1 == str2, return 0.
    If str1 > str2, return > 0.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 05:03 AM
  2. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM