Thread: strcasecmp()

  1. #1
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile strcasecmp()

    I am working on converting a vc++ prog to borland c. Also converting it from c++ to c.

    Code:
    if(  strcasecmp(argv[1],"-m")==0||strcasecmp(argv[1],"-menu")==0||
    strcasecmp(argv[1],"/menu")==0||strcasecmp(argv[1],"menu")==0||
    strcasecmp(argv[1],"-?") ==0||strcasecmp(argv[1],"/m")==0||
    strcasecmp(argv[1],"/?")==0){
         menu(); //goto menu
         return 0;
         }
    Apperently borland has no strcasecmp(). Not sure if strcasecmp is vc++ standard or a custom function. I tryed to

    Code:
    #define strcasecmp strlwr
    
    and then
    #define strcasecmp strcmpi
    and recieved "could not find a match for" error

    strcasecmp() is not defined in string.h
    would you have a template or function for strcasecmp()?

    I think it might look something like this.
    Code:
    void strcasecmp(){
    
    for(a=0;a<(sizeof(string1));a++){
                                                   test =strcmp(string1[a],string2[a]);
    an so on...
    When I replaced strcasecmp() with strcmpi() I still get errors.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I think it might look something like this.
    Code:
    void strcasecmp(){
    No, it wouldn't look like that. Take a few seconds to actually think about the problem and you'll see it's obvious that there's no way that would work.

    1) How are you supposed to check its return value if you have it returning void?
    2) How are you supposed to check its arguments if you don't make it take any?

    And finally...

    This smacks of homework. It is posted here all the time. Do it yourself. It's not that hard.

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

  3. #3
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Borland should have strcmpi and strcmp in <string.h> (<cstring> in C++). If not, that sucks .
    Do not make direct eye contact with me.

  4. #4
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile type

    it would not be a void it would be an int if anything. I was trying to show what I think the function does.

    I was asking if there is a differance between

    Code:
    strcasecmp()
    
    and
    
    strcmpi()
    I was also asking for the correct function posted (if it is a standard vc++ include file)

    I did a search before I posted and only 6 items containing strcasecmp() came up. None answered the questions I have. Only one said strcmpi() could be used with windows but not if they were the same. When I replaced strcasecmp() with strcmpi() I still get errors. This is not homework. I was trying to figure out why I get errors and to get the prog converted. Thank you for the reply

    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;   
    }
    --------------------------------------------------------------------------------
    Last edited by kryptkat; 11-13-2003 at 10:17 AM.

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    22

    Quzah!

    Listen even if you are the owner of the group or whatever form of guru you take yourself to be, i despise the way you come at people. You think we don't even think about the problems at all?

    If you are blessed with some knowledge and you are finding it very difficult to help anyone then shut it.

    I believe you are free to ignore people's problem here. I wonder how you'd react if you are getting shyt being thrown back in your face like that...

    Mister C...

    You can remove me from your group that's ok..but youhave to understand that you are being too arrogant. I can't stand arrogant fellas.
    M

  6. #6
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    no offense, but that post was not arrogant at all IMO. He is trying to point that person in the right direction and trying to get them to help themselves.

    Also, if you're going to attack a member, please do it by PM. Thanks!

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    There's usually some variant of a case insensitive strcmp, but the names are usually different so you may have to search. Of course, the implementation is fairly trivial to hand roll:
    Code:
    int no_case_cmp ( const char *s1, const char *s2 )
    {
      while ( toupper ( *s1 ) == toupper ( *s2 ) ) {
        if ( *s1 == '\0' )
          return 0;
        s1++;
        s2++;
      }
    
      return *(unsigned char *)s1 < *(unsigned char *)s2 ? -1 : +1;
    }
    >i despise the way you come at people
    Your opinions matter to us. Oh wait, no they don't. At least not when you haven't proven your worth to the community before posting hypocritical nonsense.

    >If you are blessed with some knowledge and you are finding it very difficult to help anyone then shut it.
    From what I've seen, quzah offers help quite readily and skillfully. If you want sugar coating on all of the posts you read, the forum does have an ignore feature. But be warned, you would be effectively killing posts from Salem, Sayeh, quzah, and myself. Most everyone here will agree that this would be an unwise decision.

    >I believe you are free to ignore people's problem here.
    You're free to ignore people's replies as well.

    >but youhave to understand that you are being too arrogant
    Arrogance goes with the territory. Get used to it or get another hobby.

    >I can't stand arrogant fellas.
    Finally, the root problem. The problem isn't with quzah, it is with you and your attitude. I suggest you fix it before you get an ulcer.

    [edit]
    On a side note, don't post to a thread unless you have something meaningful to add to it. You're not going to change quzah's personality any more than everyone else who tried it before you, and posting a flame to a legitimate question thread obscures the legitimate replies.
    [/edit]
    Last edited by Prelude; 11-13-2003 at 09:39 PM.
    My best code is written with the delete key.

  8. #8
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    Smile got prog working

    Thank You all. I got the prog working with strcmpi(). I was looking through str.h and string.h to see what was there. after a few changes it worked. it compiled with borland free command line tools 5.5 with a few warnings but it did run after some fustration.

    The example function I posted was not meant to be a duplicate function but to show what I thought the function did. I was alittle thrown back by the homework comment. I was like to convert from vc++ to borland what school teaches that? I addmit it might look like homework but asking a question like is stricmp() and strcmpi() and strcasecmp() the exact same eventhough they might be interchangeable? is a fair question when I know strcmp() but since strcasecmp() not defined with borland I not use that.

    I am glad that the errounius function was pointed out. I know I would have caught that sooner or later (with compile errors). I know sometimes I do not phrase questions correctly and by giveing a quick example I hope to get the idea accross.

    thank you all for the replys.

  9. #9
    Registered User
    Join Date
    Sep 2003
    Posts
    22

    Wow

    I believe you prelude, i was going through some notes regarding programmers and hackers in general. I discovered that it's just the way things goes. I'm sorry if i had been naive and immature.
    Quzah, and the likes keep up the good work. I apologized for my stupidity.Don't be too harsh on me ok..
    Peace.
    M

Popular pages Recent additions subscribe to a feed