Thread: stricmp() where can I view the sample code?

  1. #1
    Unregistered
    Guest

    Talking stricmp() where can I view the sample code?

    I need a case insensitive string comparison function similar to strcmp...where can I view the code sample of it?
    please help

    thank you

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: stricmp() where can I view the sample code?

    Originally posted by Unregistered
    I need a case insensitive string comparison function similar to strcmp...where can I view the code sample of it?
    please help

    thank you
    It's simple enough to make your own. Just loop through each string changing the characters to lower case, then use strcmp(). Well, that's one way, there are more...

    You'll need to use isupper() and tolower() at least.....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Re: stricmp() where can I view the sample code?

    Originally posted by Hammer

    You'll need to use isupper() and tolower() at least.....
    Actually, you'll need only 'toupper' or 'tolower' only. One or the other. No need for both, no need to even bother checking. Just run a loop and compare tolower(letter1) with tolower(letter2).

    You can pass tolower a lower case value, or hell, even a number or punctuation mark, and it'll just return any non-upper case characters as they were, unchanged. The only thing it changes is upper case.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    or if your homework does not require you to write your own you could use

    lstrcmpi() (windows version of stricmp() )

    if(lstrcmpi(sString1,sString2)==0)//they are the same
    Last edited by novacain; 06-28-2002 at 02:29 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    London, United Kingdom
    Posts
    226
    just use stricmp....

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >just use stricmp....
    Why? The functionality is trivial to program and far more portable if done correctly. Remember that stricmp is not a standard function, so not all implementations will have it. With a little thought and effort, you can write your own function in ISO conforming code and not have to worry about portability problems.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't get sample shell code to work...
    By jcafaro10 in forum C Programming
    Replies: 6
    Last Post: 07-07-2010, 08:04 AM
  2. Any sample code availble?
    By krishnampkkm in forum Windows Programming
    Replies: 1
    Last Post: 06-19-2009, 04:41 AM
  3. Linked List Tutorial sample code question
    By Kalleos in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 12:20 PM
  4. Sample C code that change character
    By dianazheng in forum C Programming
    Replies: 11
    Last Post: 05-29-2005, 08:10 AM
  5. View .htm... code in IE or Opera or Firefox
    By xxxrugby in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 03-09-2005, 07:09 AM