char*str_del_char(char* str/*, char del*/){char retstr[100];for(int i= 0, j= 0; str[i]!='\0'; i++){if(str[i] != '(' && str[i] != ')'){retstr[j++]= str[i];}}retstr[j]= '\0';return strcpy(str, retstr);}void main(){char str[100], del;printf("请输入字符串和要删除的字符:\n");/*,用空格隔开*/scanf("%s", &str);/*, %c &del*/printf("%s\n", str_del_char(str));}
#include <stdlib.h>#include <string.h>// call free for release memorychar *str_del(const char *str){int len = (int)strlen(str);char *new_str = (char *)malloc(len+1);memset(new_str, 0, len + 1);bool b_left = false;int j = 0;for(int i = 0; i < len; i ++){if(!b_left){if(str[i] != '('){new_str[j++] = str[i];}else{b_left = true;}}else{if(str[i] == ')'){b_left = false;}}}return new_str;}int main(int argc, char* argv[]){char *new_str = str_del("333333333(*safda()sdfasdf)444(44444)444");printf("new str : %s.\n");free(new_str);return 0;}