(SOLVED)Can any one help?

    if(temp >= ' ' && temp <= '~')
    {
      str[i++] = temp;
      str[i] = '\0';
    }
    if(i == 16)
    {
      return 0;

If you got a valid character, write it into the array, and append a NULL. If the NULL was written into the 17th element of a 16 element array, return 0. Do you see where this is a problem?