Bloomberg LP Interview Question
Software Engineer / Developers/*write a function to remove the spaces from a string inplace,*/
#include<stdio.h>
void main()
{
char s[50];
char *p;
int temp = 0;
int i=0;
printf("Please Enter a string ");
p = gets(s);
while(p[i]!='\0')
{
//printf("In Loop");
if(p[i]!=' ')
{
s[temp++] = p[i++];
continue;
}
else
{
//temp = i;
while(p[i] == ' ')
i++;
s[temp++] = p[i];
}
i++;
}
s[temp] = '\0';
printf("The final string is %s \n", s);
}
Same question was asked in paypal quiz. Did it well. O(n)
- Pratik March 23, 2006