ifdef

Discussion in 'C++' started by Michael Sgier, Jul 4, 2006.

  1. Hi
    I get the error:
    No case-independent string comparison (stricmp, strcasecmp)
    with the code below. Why...where should stricmp
    be defined? And how do i get rid of the error on Linux?

    //
    // Function portability
    //
    #ifndef HAVE_STRICMP
    #ifdef HAVE_STRCASECMP
    #define stricmp strcasecmp
    #else
    #error No case-independent string comparison (stricmp, strcasecmp)
    available.
    #endif
    #endif // HAVE_STRICMP


    another problem here:


    #define DEBUG 1
    main()
    {
    char inbuf[BUFSIZ];
    int i = 0;
    int lcnt = 0;
    gets(inbuf);
    while(*(inbuf+i))
    {
    #ifdef DEBUG
    printf("Character %d Value %c(%o)\n",
    i,*(inbuf+i),*(inbuf+i));
    #endif
    if(isalpha(*(inbuf+i)))lcnt++;
    #ifdef DEBUG
    printf("Letter Count %d\n",lcnt);
    #endif
    i++;
    }
    printf("Total letters %d\n",lcnt);
    }


    why is ifdef DEBUG 2x there?
    Thanks
    Michael
    Michael Sgier, Jul 4, 2006
    #1
    1. Advertising

  2. Michael Sgier wrote:
    > Hi
    > I get the error:
    > No case-independent string comparison (stricmp, strcasecmp)
    > with the code below. Why...where should stricmp
    > be defined? And how do i get rid of the error on Linux?
    >
    > //
    > // Function portability
    > //
    > #ifndef HAVE_STRICMP
    > #ifdef HAVE_STRCASECMP
    > #define stricmp strcasecmp
    > #else
    > #error No case-independent string comparison (stricmp, strcasecmp)
    > available.
    > #endif
    > #endif // HAVE_STRICMP
    >
    >
    > another problem here:
    >
    >
    > #define DEBUG 1
    > main()
    > {
    > char inbuf[BUFSIZ];
    > int i = 0;
    > int lcnt = 0;
    > gets(inbuf);
    > while(*(inbuf+i))
    > {
    > #ifdef DEBUG
    > printf("Character %d Value %c(%o)\n",
    > i,*(inbuf+i),*(inbuf+i));
    > #endif
    > if(isalpha(*(inbuf+i)))lcnt++;
    > #ifdef DEBUG
    > printf("Letter Count %d\n",lcnt);
    > #endif
    > i++;
    > }
    > printf("Total letters %d\n",lcnt);
    > }
    >
    >
    > why is ifdef DEBUG 2x there?
    > Thanks
    > Michael


    This is not a C++ question.
    You'll get more detailed answers in the GCC newsgroup:

    gnu.gcc.help

    On my linux system with gcc v3.3.5 strcasecmp()
    is declared in strings.h, but HAVE_STRCASECMP is NOT
    defined. This looks like part of an automake/config
    system where automake sets the defines (eg HAVE_STRCASECMP)
    based on its inspection of your system. If you do
    have strcasecmp() in /usr/include/strings.h you can
    define HAVE_STRCASECMP yourself.

    Regards,
    Larry
    Larry I Smith, Jul 5, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    611
  2. Replies:
    1
    Views:
    728
    Kevin Spencer
    May 31, 2005
  3. Replies:
    4
    Views:
    2,359
    Peter Flynn
    Jan 15, 2006
  4. F. Edward Boas

    typedef and #ifdef

    F. Edward Boas, Aug 11, 2003, in forum: C++
    Replies:
    1
    Views:
    964
    Alf P. Steinbach
    Aug 11, 2003
  5. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,086
Loading...

Share This Page