Page 98, Exercise 3 strdel()

 

Call:
strndel("doghouse",0,3,s2);
void strdel(char *s, char ch)

{/*Exercise 3: remove first occurence of c from s */

   char cpy[MAX_SIZE];

   int i= 0;

   while (i < strlen(s))

      if (s[i] == ch) break;

	  else cpy[i] = s[i++];

	if (i < strlen(s)) {

	   i++; /*skip ch */

	   while (i < strlen(s))

	      cpy[i-1] = s[i++];

	 }

	 cpy[i] = '\0';

	 strcpy(s,cpy);

}