《c程序设计语言》读书笔记-删除字符串中匹配的字符
#include <stdio.h> #include <string.h> #define Num 10 int main() { int c,i,j = 0,m,n = 0,count1 = 0,count2 = 0; char s[Num],t[Num],st[Num],str[Num]; printf("Please input a string:\n"); while((c = getchar()) != EOF && c != '\n' && count1 < Num) { s[count1] = c; count1++; } printf("Please input another string:\n"); while((c = getchar()) != EOF && c != '\n' && count2 < Num) { t[count2] = c; count2++; } for(i = 0; s[i] != '\0' && i < count1; i++) { if(s[i] != t[i]) { st[j] = s[i]; j++; } } for(i = 0; t[i] != '\0' && i < count2; i++) { if(s[i] != t[i]) { str[n] = t[i]; n++; } } for(m = 0;m < j ;m++ ) { printf("%c",st[m]); } printf("\n"); for(m = 0;m < n ;m++ ) { printf("%c",str[m]); } return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步