StrCmp

This is a discussion on StrCmp within the C Programming forums, part of the General Programming Boards category; Can someone show me what StrCmp looks like written out?...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    57

    StrCmp

    Can someone show me what StrCmp looks like written out?

  2. #2
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    This was taken from the help file from my compiler : Borland c++ 5.02

    Code:
    #include <string.h>
    #include <stdio.h>
    
    int main(void)
    {
        char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
        int ptr;
    
        ptr = strcmp(buf2, buf1);
        if (ptr > 0)
            printf("buffer 2 is greater than buffer 1\n");
        else
            printf("buffer 2 is less than buffer 1\n");
    
        ptr = strcmp(buf2, buf3);
        if (ptr > 0)
            printf("buffer 2 is greater than buffer 3\n");
        else
            printf("buffer 2 is less than buffer 3\n");
    
        return 0;
    }

    theres also an "strcmpi" that compares without case sensitivity
    Last edited by biosninja; 11-21-2002 at 11:57 PM.

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    theres also an "strcmpi" that compares without case sensitivity
    Its not compaticle with ANSI i guess its a borland function ??
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    57
    No I mean the function itself not using it.

  5. #5
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    No I mean the function itself not using it.
    ?

    string compare?

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    he wants to see the actual function's code...

  7. #7
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655
    i think he means like whats string compare doing??????
    guns dont kill people, abortion clinics kill people.

  8. #8
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    i think he means like whats string compare doing??????
    strcmp performs an unsigned comparison of s1 to s2, starting with the first character in each string and continuing with subsequent characters until the corresponding characters differ or until the end of the strings is reached.

    Return Value

    If s1 is... return value is...

    less than s2 < 0
    the same as s2 == 0
    greater than s2 > 0


    s1 = string 1
    s2 = string 2

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    From K&R2
    Code:
    /* strcmp:  return <0 if s<t, 0 if s==t, >0 if s>t */
    int strcmp(char *s, char *t)   
    {      
        for ( ; *s == *t; s++, t++)
               if (*s == '\0') return 0;
        return *s - *t;   
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

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, 05:30 PM
  2. help with switch statement
    By agentsmith in forum C Programming
    Replies: 11
    Last Post: 08-26-2008, 04:02 PM
  3. problem with strings
    By agentsmith in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 12:07 PM
  4. help with strcmp
    By blork_98 in forum C Programming
    Replies: 8
    Last Post: 02-21-2006, 07:23 PM
  5. strcmp
    By kryonik in forum C Programming
    Replies: 9
    Last Post: 10-11-2005, 11:04 AM

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