I changed the *(starpos) = '\0'; to *(starpos-1) = '\0'; but no change.