问一下,我想输入一串字符删除字母a后输出,就像输入‘ancd’得到‘ncd’这样子啊
虚心求教~~
#include<stdio.h>
#include<string.h>
#define MAXSIZE 225
typedef struct
{
char str[MAXSIZE];
int length;
} SeqString;
int StrDelete(SeqString *S, int i, int len)
{
int k;
if(i < 1 || i > S->length || i - 1 + len > S->length)
return 0;
else
{
for(k = i - 1 + len; k < S->length; k++)
S->str[k - len] = S->str[k];
S->length = S->length - len;
S->str[S->length] = '\0';
}
printf("删除之后的字符串:");
printf("%s\n", S->str);
return 0;
}
int main(void)
{
SeqString s1;
int i, length;
printf("请输入源子串:");
scanf("%s", s1.str );
printf("字符串长度为:%d\n", s1.length = strlen(s1.str ));
printf("请输入要删除的位置:");
scanf("%d", &i);
printf("请输入删除的长度:");
scanf("%d", &length);
StrDelete(&s1, i, length);
}
你试试。