2-4编写函数squeeze(s1,s2),将字符串s1中与字符串s2中字符匹配的字符都删掉
#include<stdio.h> #define max 100 void squeeze(char* leftStrig,char* rightString); int main(){ char left[100]="shizhendema"; char right[100]="bushizhende"; char* result=""; // printf("%s\n",result); squeeze(left,right); //printf("%s\n",result); return 0; } void squeeze(char* leftString,char* rightString) { int i; int j; int k=0; char rlString[max]; for(i=0;leftString[i]!='\0';i++) { for(j=0;rightString[j]!='\0';j++) { if(leftString[i]==rightString[j]) break; } if(rightString[j]=='\0') { rlString[k]=leftString[i]; k++; } } rlString[k]='\0'; printf("%s\n",rlString); }
#include<stdio.h> char* aString() { //char s[100]="abc"; //这样是不行的 char* s = new char[100]; s="abc"; return s; } int main() { char* s; s=aString(); printf("%s\n",s); return 0; }