Question(s) concerning case insensitive string comparisons

This is a discussion on Question(s) concerning case insensitive string comparisons within the C Programming forums, part of the General Programming Boards category; First a compiler question...then the REAL question. Given this strucutre... Code: typedef struct Key KEY; typedef struct Key* KEYS; struct ...

  1. #1
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72

    Question Question(s) concerning case insensitive string comparisons

    First a compiler question...then the REAL question.

    Given this strucutre...
    Code:
      typedef struct Key  KEY;
      typedef struct Key* KEYS;
    
    struct Key 
      {
          char *sender;
          char *addressee;
          char *regarding;
          DATE date;
          int id;
          char *fname;
          KEYS next;
      };
    why would my compiler complan that there is a signed/unsigned mismatch with this for loop statement?
    Code:
    KEYS search(KEYS k, KEY ki )
    {
    ....some code....
    
        for(i=0;i<=strlen(ki.sender); i++)
              temp.sender[i]=tolower(ki.sender[i]);
    
    
    ...some more case conversion
    }
    what's weird is that the compiler does not complian if I do it like this.
    Code:
    len=strlen(ki.sender)
    for(i=0;i<=len; i++)
          temp.sender[i]=tolower(ki.sender[i]);
    utlimately, what I am trying to do is prepare two strings for a non-case sensitive comparison. So that "BARBARA" would match "Barbara".

    Is there an easier (or more clever) way to do this operation on a string beside the way I am trying to do it in the for loop up above? I hate using the temp.


    Thanks,
    Mike
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    22
    Hi,
    Use strcasecmp()

    #include <strings.h>
    int strcasecmp(const char *s1, const char *s2);

    available on most flavours of unix.

    by
    A.Sebasti..

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    65
    You may use strcmpi in most DOS/Windows compilers.

    #include <string.h>

    int strcmpi (const char *s1, const char *s2);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-05-2009, 11:32 AM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. wildcard case insensitive string compare
    By lawina in forum C Programming
    Replies: 3
    Last Post: 06-13-2006, 04:27 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM

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