Problem #1:
Your function returns a pointer to a (temporary) string which is allocated on the stack. This means that once your function ends, the memory for rtn is released, and this invalidates the char * pointer that the function returns.
What you would rather do is:
void getstring(char str[], char rtn[])
{
/* Some processing on rtn... */
}
The caller to getstring should handle the allocation and deallocation of the string passed as rtn.
Problem #2:
Your while loop will run indefinitely, because i never increases. Put i++ somewhere inside the loop.
Problem #3:
The condition in your if-statement is faulty. You compare str[i], which is a char, to " " or "$", which are string literals (having '\0' in the end). This is wrong.
You need to compare them to chars, which are indicated by apostrophes (not quotation marks).
Also, note that the test condition is wrong as well. You need a logical AND operator instead of OR.
Change the if-statement to:
if (str[i] != ' ' && str[i] != '$')
Problem #4:
What does rtn[i] = ''; mean? '' is an empty character constant, which is illegal in C.
Did you want to just skip a character in str?
Problem #5:
You have indexation problems. Because str and rtn may obviously be of different length, you need to manage two running indices, one for each string.
Problem #6:
rtn is not necessarily null-terminated when the function returns. Assign '\0' to the end of rtn before the function returns (i.e. rtn[i] = '\0'; after the while-loop ends).
Here's your code with all the problems mentioned above fixed:
void getstring(char str[], char rtn[])
{
int i = 0, j = 0;
while (i < strlen(str))
{
if (str[i] != ' ' && str[i] != '$')
rtn[j++] = str[i];
i++;
}
rtn[j] = '\0';
}
And here's a more efficient version that uses pointers instead of indices, and doesn't use strlen:
void getstring(char *str, char *rtn)
{
while (*str)
{
if (*str != ' ' && *str != '$')
*rtn++ = *str;
*str++;
}
*rtn = '\0';
}