strcmp clarification

This is a discussion on strcmp clarification within the C Programming forums, part of the General Programming Boards category; Ola! if I use the function int my_strcmp(char * s1, char * s2) { /* S1 = Abba S2 = ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    strcmp clarification

    Ola!

    if I use the function

    int my_strcmp(char * s1, char * s2)
    {
    /* S1 = Abba S2 = Ball*/
    return strcmp(s1,s2);
    }

    What will the function return? Will it be a +ve integer or negative? (Basically I'm asking how and what does strcmp return when you know the strings aren't equal?)

    Thanks for your help!

  2. #2
    Nit
    Nit is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    42
    strcmp(s1, s2)

    returns 0 if they are equal. returns 1 if s1 is greater than s2 and returns -1 if s1 is less than s2.
    http://www.KBeutler.com

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    >Ola!

    Word!

    Since A<B, it should return a negative.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fucntion returns -1, Why?
    By Taper in forum C Programming
    Replies: 16
    Last Post: 12-08-2008, 06:30 PM
  2. help with switch statement
    By agentsmith in forum C Programming
    Replies: 11
    Last Post: 08-26-2008, 05:02 PM
  3. problem with strings
    By agentsmith in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 01:07 PM
  4. help with strcmp
    By blork_98 in forum C Programming
    Replies: 8
    Last Post: 02-21-2006, 08:23 PM
  5. strcmp
    By kryonik in forum C Programming
    Replies: 9
    Last Post: 10-11-2005, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21