S
sara
Hi,
I have implemented the following method to remove all the occurences
of c from string s.
void squeeze(char* s, char c)
{
char string[]="";
strcpy(string,s);
int src=0;
int dst=0;
while(string[src]!='\0')
{
while (string[src]!='c')
{
src++;
if (string[src]!='\0')
dst++;
}
if (string[src]=='\0')
break;
while(string[src]=='c')
src++;
string[dst]=string[src];
}
string[dst+1]=0;
return;
}
How can I change the fucntion to return the string variable? If I make
the function 'char[] squeeze(char* s, char c)' it does not compile and
if I make it 'char* squeeze(char* s, char c)' I got some weird error.
Also, is it possible to write the functon more efficiently?
I have implemented the following method to remove all the occurences
of c from string s.
void squeeze(char* s, char c)
{
char string[]="";
strcpy(string,s);
int src=0;
int dst=0;
while(string[src]!='\0')
{
while (string[src]!='c')
{
src++;
if (string[src]!='\0')
dst++;
}
if (string[src]=='\0')
break;
while(string[src]=='c')
src++;
string[dst]=string[src];
}
string[dst+1]=0;
return;
}
How can I change the fucntion to return the string variable? If I make
the function 'char[] squeeze(char* s, char c)' it does not compile and
if I make it 'char* squeeze(char* s, char c)' I got some weird error.
Also, is it possible to write the functon more efficiently?