Delete the words that mathes to the key. It's not my homework i learn "c" by myself.
I wrote this
It deletes the word only when it has n+2-spaces after it.
Ex: I was"+5 spaces" very happy. in this case it will delete the word "was" correctly.
I wrote this
Code:
int wdel(char* a, char* key){ // (a) is the string and (key) is the word if(!a || !key) return 0; int i,k=0,l,n; char *p; n=lens(key); //(n) is the lenght of the word i want to delete for(i=0;a[i]!=0;i++){ if(a[i]==key[k]) { l++; k++; } if(a[i]==' ') { l=0; k=0; } if(l==n){ p=&a[i]; strcpy((p-n)+1,p+1); } } return 1; }
Ex: I was"+5 spaces" very happy. in this case it will delete the word "was" correctly.
Comment