(SOLVED)Can any one help?

You seem to be confused about how NULL termination of strings occurs. There is nothing magic about it. YOU must NULL terminate the array. The best time to do that is after EVERY character is added to the array.

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

You also seem confused about the return codes from the function.