第1个回答 2011-06-10
找到A中B的子串。。然后把后面的覆盖过来。。
追问我是个新手。。。用什么函数覆盖。。可以举例么。。
有些晕。。a[i]=[i+1]么?
追答你可以先找到字串位置使用STRSTR函数会返回字串在母串的起始位置。。然后保存下来。。通过字串的长度在得到字串结束位置的指针。。直接使用strcpy把字串后的母串覆盖到原来字串的位置
你愿意a[i] = a[i+1]也行。。
第2个回答 2011-06-10
#include "stdio.h"
#define MAXSIZE 50
void DeleteStr(char a[],char str[]);
int GetLength(char a[]);
int main()
{
char a[MAXSIZE];
char b[MAXSIZE];
scanf("%s",a);
scanf("%s",b);
DeleteStr(a,b);
printf("%s\n",a);
return 0;
}
int GetLength(char a[])
{
char *p = a;
int len = 0;
while (*p !='\0' )
{
len++;
p++;
}
return len;
}
void DeleteStr(char a[],char str[])
{
int n = 0;
int i = 0;
int len_a = GetLength(a);
int len_str = GetLength(str);
while (n < len_a)
{
while (a[n+i] == str[i] && str[i] != '\0')
{
i++;
}
if (str[i] == '\0')
{
int k = n;
while(1)
{
a[k] = a[k+len_str];
if (a[k] == '\0')
{
break;
}
k++;
}
i = 0;
}
n++;
}
}本回答被提问者采纳
第3个回答 2011-06-11
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s[]="123abcZXY",b;
int i,j,L,big=0;
printf("orig string: %s\n",s);
L = strlen(s);
for (i=1;i<L;i++) if (s[i] > s[big] ) big=i;
b=s[big];
for (i=big;i>0;i--) s[i]=s[i-1];
s[0]=b;
printf("results: %s\n",s);
return 0;
}
--
orig string: 123abcZXY
results: c123abZXY
第4个回答 2011-06-10
char *c;
char *d;
c = strstr(A,B);
if (NULL != c)
{
d = c+strlen(B)-1;
strcpy(c,d);
}