I'm trying to figure out an algorithm. Given a string (as an array), the
function has to take out redundant characters. ie :
Given : Hello how are yoo
function returns : Helo are yo
function prototype : void trim (char *string);
I have to implement this function in two versions; one using arrays, the
other using pointers.
Please help, thanks,
Using arrays or pointers is just the same. The difference is only in the
addressing scheme, the algorithm is the same. You should use two pointers.
One goes ahead and the other follows. If the character to be copied is the
same as the previous was then only the first one is increased.
This is that simple. I assume that this is a homework, so beter you figure
out how to code it in C so that you learn from it.
[ back to toc ]