It works because it starts off by doing *p='\0'; to initialise a very small counter to zero.
It's basically using a position in the array as a temporary counter before overwriting it with the modified string.
It does however run into serious problems if the number of characters after the first 's' is more than can be represented in the positive part of a char (say 127 or 255 typically). As soon as that wraps around, then it's bye bye code.
> but to my faculty who had asked the original question..
Is that the same person who told you to use gets() ?
Perhaps you could point out these bugs to your tutor.