Thread: <strings.h>

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    17

    <strings.h>

    Anyone know where I can get that?
    I need the strncasecmp() function to compare two strings regardless of their case.

    I can't find it anywhere, and it doesn't come with my compiler im using.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    try stricmp() or strnicmp(). I'm willing to bet you have those functions.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    FAQ > How do I... (Level 1) > Where can I download a missing header file?

    <string.h> is a standard header, not <strings.h>, but strcasecmp is not a standard function. Writing your own is fairly easy. [edit]Take a stab at it before peeking at this.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    17
    I don't have either of those functions.

    Im using strncmp() but I need something that will say the strings are the same if for example:
    1) This Is A String
    2) this is a string

    I need both of those to be compared and the function to return that they are the same. Right now the strncmp() does not do this.

    I only have the <string.h> header file, but in the <strings.h> file there is the strncasecmp(), in which I need.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    What compiler are you using?

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    17
    The linux gcc compilers in our computer labs have this header file, but my windows compiler does not have this, and I cannot get to the lab to grab it.

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    17
    I'm just using a compiler I grabbed off a site called PellesC.

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    As, Dave said. It's easy to write your own. Look into <ctype.h> and the toupper() function. You don't go fishing around for nonstandard libraries when it's easy enough to write the code using standard libraries.
    Sent from my iPadŽ

  9. #9
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    Doesn't using non-standard headers defeat the whole purpose of writing portable C code (which made C famous in the first place)?

  10. #10
    Registered User
    Join Date
    Jun 2006
    Posts
    4
    I'm sort of a beginner at this but wouldn't stricmp() work?

  11. #11
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Quote Originally Posted by bigggame
    wouldn't stricmp() work?
    I'm also wondering...
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  12. #12
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Plese try to compile the following code and place error messages you're getting:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main (void)
    {
        char str1[] = "Test";
        char str2[] = "test";
        
        printf ("%d", stricmp (str1,str2));
        return 0;
    }
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  13. #13
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by bigggame
    I'm sort of a beginner at this but wouldn't stricmp() work?
    Quote Originally Posted by Jafet
    I'm also wondering...
    Beginner at reading, I guess. He already said.
    Quote Originally Posted by Sev3r
    I don't have either of those functions.
    How he doesn't, I don't know, but regardless, it's simple enough to write one.
    Sent from my iPadŽ

  14. #14
    ex-DECcie
    Join Date
    Dec 2005
    Posts
    125

    Depends on your requirements.

    Quote Originally Posted by cdalten
    Doesn't using non-standard headers defeat the whole purpose of writing portable C code (which made C famous in the first place)?

    If portability is a requiement, yes.

    If it is not a requirement, or not particularly cared about, then no.
    Mr. Blonde: You ever listen to K-Billy's "Super Sounds of the Seventies" weekend? It's my personal favorite.

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I don't have either of those functions.
    Try _strnicmp() for MS compilers.

    The best solution is to write your own string comparison function.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed