char* Delete(char *s1,char c) { char *s2; //the new string int n1,n2=0,n3; n1=strlen(s1); //find the length of my string while(*s1!='\0') //in this loop i find how many characters is similar to c { if(*s1==c) n2++; s1++; } n3=n1-n2; //find the length of new string s2 s2=(char *)malloc((n3+1)*sizeof(char)); while(*s1) { if(*s1!=c) { *s2++=*s1; } s1++; } *s2='\0'; return s2; } int main() { char s1[20],c; scanf("%c\n",&c); gets(s1); printf("The new string is: %s",Delete(s1,c)); return 0; }
s1
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)