C语言中 如何把字符串中某一位清空?

对比了B与A两个 字符串。。想要把A中包含B的部分别删除。。。
但是不知道怎么做。。求高手帮忙。。。
for(j=0;b[j]!='\0';j++)
for(i=0;a[i]!='\0';i++)
if(b[j]==a[i])

a[i]='0'
比如可以做到
A=77533aasds3a112
B=3a
运行之后
A=7753asds112

假设这个一维字符串数组是str[80]----不一定是一维字符串数组,多维数组,结构都可以。

方法1:使用运行库函数memset():
memset(str, 0, sizeof(str));

方法2:使用Windows API函数ZeroMemory():
ZeroMemory(str, sizeof(str));

但不能用于指针。指针的情况下,必须这样:
struct mystr *p;
...
memset(p, 0, sizeof(struct mystr));
或:
ZeroMemory(p, sizeof(struct mystr));
温馨提示:答案为网友推荐,仅供参考
第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);
}
相似回答