#includestdio.h
char * func(char *s)
{
int i,j = 0;
for(i = 0; i strlen(s);)
{
if(s[i] == ' ')
{
i++;
}
else
{
s[j] = s[i];
j++;
i++;
}
}
s[j] = '\0';
return s;
}
int main()
{
This is doing a leftshift equivalent right?
its asked if there is another solution..
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/vc7DL3vWVy8J.
To post to
#includeiostream#includestdlib.husing namespace std;char *
remove_spaces(char *s){
char *result;
char *temp;
temp=s;
result=s;
while(*s!='\0')
{
if(*s==' ')
{
s++;
}
else
{
*temp = *s;
temp++;
s++;
This solution doesn't work.
It prints a blank string.
I think because sometimes the condition becomes true only when a space is
encountered. After which when we shift the value what happens to the value
at the position where we are shifting from. It will still contain the char.
This would be