Re: [algogeeks] Re: Given a String with unnecessary spaces, compact it in place

2011-11-10 Thread UTKARSH SRIVASTAV
#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() {

[algogeeks] Re: Given a String with unnecessary spaces, compact it in place

2011-10-16 Thread sravanreddy001
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

Re: [algogeeks] Re: Given a String with unnecessary spaces, compact it in place

2011-10-14 Thread veera reddy
#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++;

Re: [algogeeks] Re: Given a String with unnecessary spaces, compact it in place

2011-10-13 Thread janani thiru
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