Coding challenge

Posted by Darin Rousseau | Filed under ,

During the hiring process, Fundamental Software Solutions has always passed small tests of skill to potential developer hires.  We don't ask much - just spot some commonly made mistakes, or identify what will most likely happen with some sample code.  Now, we haven't been been the only ones doing this - and for good reason.  Programming skill is highly varied.  Does it work?  So far.

Now for some fun.  We have stumbled across the results of one particular interviewee of a pretty major company looking for C++ programmers.  The interviewee was asked to create a small, efficient program that would take the input from a user and make it lowercase, without using any pre-made library functions to do the 'lowercasing.'  The text will be plain, old ascii english characters, so don't worry about UNICODE or anything like that.

Here is a modified result of what was written.  (We modified it to protect the job seeker from being googled, but the code is essentially the same.)

  1. char * MakeTextLower(char *ptr) 
  2. {   
  3.    while (*ptr != '\0'
  4.    {   
  5.       if (*ptr > 'A' && *ptr < 'Z'
  6.       {   
  7.          *ptr -= 'A' - 'a';   
  8.       }   
  9.       *ptr++;   
  10.    }   
  11.    return ptr;   
  12. }  

 There are at least two problems with this code that make it non-functional.  Can you spot them? 

 [Edit: For extra credit, the function is also going to return the wrong thing.  Can you tell us what will be returned?]