定义三个字符串:str[], ab[], output[],str是输入的第一个字符串,output放的是最后的结果。设置两个下标 i,j。i指向第一个字符串,j指向第二个子符串;i每次向后移动一个位置,i往后的strlen(ab)个字符是不是和字符串ab匹配,如果不匹配就把str[i]添到字符串output中,如果匹配,就让i直...
m++;} printf("字符串%s中有ab字符的个数为:%d",g,m); //改为g } 函数应用:1、连接运算 concat(s1,s2,s3…sn) 相当于s1+s2+s3+…+sn.例:concat(‘11’,'aa’)='11aa’;2、求子串。 Copy(s,I,I) 从字符串s中截取第I个字符开始后的长度为l的子串。例:copy(‘abdag’,2,3...
算法是用字符数组存储字符串,逐个比较数组的值是否等于ab,让人编程还不多给分。。。算了帮你写一下吧 char str[1000]=-1;(这是为了方便确定字符串的结尾)scanf(……)这个自己写吧 n=0;for(i=0;str[i]!=-1&&str[i+1]!=-1;i++){ if(str[i]=='a'&&str[i+1]=='b')n+=1...
include<stdio.h> include<string.h> include<stdlib.h> char *my_delsub(char *str,char *sub){ char *p,*str2;char *t;int i=0;t=(char *)malloc(strlen(str));str2=str;p=sub;while(*str2){ while(*p){ if(*p==*str2)break;p++;} if(*p=='\0'){ t[i]=*str2;i...
可以用字符串函数的话 可以这样 void func(char *src, char *a, char *b, char *dst)//将src中,a和b中间的字符串复制到dst中。{ char *p1, *p2; p1 = strstr(src,a); p2 = strstr(src,b); if(p1&&p2) { p1+=strlen(a); strncpy(dst, p1, p2-p1);...
include "stdio.h"include "stdlib.h"include "string.h"include "conio.h"int main(){ char s[1000],c;int i;scanf("%s",s);c=getche();printf("\n\n");for(i=0;i<strlen(s);i++){ if(s[i]!=c)printf("%c",s[i]);};system("pause");return 0;};...
]){ char A[N+N],B[N],C[N],t[N+N],*p;printf("Please enter the three strings...\n");scanf("%s%s%s",A,B,C);if(p=strstr(A,B)){ strcpy(t,p+strlen(B));strcpy(p,C);strcat(A,t);printf("\n%s\n",A);} else printf("A not B...\n");return 0;} ...
不是错误 只是提醒你字符串不能修改 还有头文件没包含全 include<iostream>#include<cstring>#include<cstdio>#include<vector>using namespace std;void Combination(const char* string, int number, vector<char>& result)//const{ if(number == 0) { vector<char>::iterator iter = r...
只要扫描整个字符串,将找到的'a'换为'b'即可。然后输出整个字符串。include<stdio.h> int main(){char s[200];int i;gets(s); //获取字符串 for(i=0;s[i];i++) //扫描串 if(s[i]=='a') //若符合要求 s[i]++; //将'a'换为'b'puts(s); //输出整个字符...
void main(){ char a[N]={’\0’},b[N]={’\0’},ch,max;int i,j,k,c;/输入字符串/ printf(“请输入字符串”);gets(a);/输入ch的值/ printf(“Input ch:”);scanf("%c",&ch);/求出最大字符/ i=1;max=a[0];while(a[i]!=’\0’){ if(a[i]>max)max=a[i];i...