Many people (especially, with articles like this) miss the distinction between the writer and the written-up. One of the hard things --- as an editor and as a coder --- is to not just blurt out all the answers: that ruins the fun for everyone at the sake of being only slightly less incomplete. When there is a "challenge" to re-write something, it's just for fun and we should probably refrain from making it personal.

That being said, I've got the hint that many of you like string functions. Here's one John found. Yes, it's C++; and yes, they're working with char*. I'll assume you can figure out why it's called strcmpi.


  int strcmpi (const char*csz1, const char*csz2)
      int iRetval= 0;

      char *p1= NULL, *p2= NULL;

      if ((csz1 != NULL) && (csz2 != NULL)) {
          int iLen1= 0, iLen2= 0;

          iLen1= strlen (csz1);
          iLen2= strlen (csz2);
          if (iLen1 > 0) {
              p1= new char [iLen1+1];
              memset (p1, 0, iLen1+1);
              strcpy (p1, csz1);
              for (int i=0;i<iLen1;i++) {
                  p1[i]= toupper (p1[i]);
          if (iLen2 > 0) {
              p2= new char[iLen2+1];
              memset (p2, 0, iLen2+1);
              strcpy (p2, csz2);
              for (int i=0;i<iLen2;i++) {
                  p2[i]= toupper(p2[i]);

          if ((p1!=NULL) && (p2!=NULL))
              iRetval= strcmp (p1, p2);
          else iRetval= -1;

          if (p1 != NULL)
              delete [] p1;
          if (p2 != NULL)
              delete [] p2;

      return iRetval;


And what did John take away from all this?

Someone once said if you can't implement any O(n) string function in two lines, you are not a programmer. The guy who wrote this string compare function is apparently 20 times the normal programmer!


[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!