從字符串s中刪除指定的字符 c語言程序中,從字符串s中刪除指定的字符c?
c語言程序中,從字符串s中刪除指定的字符c?沒有函數(shù),#include<stdio。H>void main(){TCHAR s[80],CH/tint I,J/tprintf(“input s
c語言程序中,從字符串s中刪除指定的字符c?
沒有函數(shù),#include<stdio。H>void main(){TCHAR s[80],CH/tint I,J/tprintf(“input string:”)tgets(s)tprintf(“input the specified character to delete CH:”)TCH=getchar()t for(I=J=0s[I]!=“0”I)T/TIF(s[I]!=CH)s[J]=s[i]TS[J]=“”0“t打印(”刪除字符%C后,字符串為%sn”,CH,s) }
用C語言編寫從字符數(shù)組S中刪除存放在數(shù)組C中的字符的程序,急,在線等?
]#<stdio.h>
#include<malloc.h>
#include<string.h>
void deleteChar(char*s,char*c)
{
int slength=strlen(s)
int clength=strlen(c)
int*target=(int*)malloc(slength*sizeof(int))
for(int i=0i<slengthi)
{
target i=0
for(i=0i<slengthi)
for(int j=0j<clengthj)
{
if(s[i]==c[j])
target[i]=1
}
for(i=0i<slengthi)
printf(%d,target[i])
printf(“n”)
for(i=0i<slengthi)
{
if(target[i]==1)
{
for(int j=i 1j<slengthj))
{
if(target[j]==0)
{
s[i]=s[j
]s[j]=“0”
target[j]=1
break
}
}
}
free(target)
}
void main()
{
char a[]=“abcdef”
char b[]=“bd”
deleteChar(a,b)
printf(%sn”,a)
}