#define MAXLEN 50/*2009/09/18晚 写于白鹿原*/ typedef struct /*顺序串的删除操作*/ { char ch[MAXLEN]; int len; }SString; void StrAsign(SString *s)//串的建立函数 { int i,j; char c; printf("/nPlease input the length of String:"); scanf("%d",&j); getchar(); printf("/nplease input the value of String:"); for(i=0;i<j;i++) { scanf("%c",&c); s->ch[i]=c; } s->len=j; } void output(SString *s)//串的输出 { int i; for (i=0;i<s->len;i++) printf("%c",s->ch[i]); printf("/n"); } int StrDelete(SString *s,int pos,int len)/*在串s中删除从下标pos起len个字符*/ { int i; if(pos<0||pos>(s->len-len)) return 0; for(i=pos+len;i<s->len;i++) s->ch[i-len]=s->ch[i];/*从pos+len开始至串尾依次向前移动,实现删除字符*/ s->len=s->len-len; return 1; } void main() { int pos,flag,len; SString *s1; s1=(SString *)malloc(sizeof(SString)); s1->len=0; printf("/nNOW Please input the String!"); StrAsign(s1); printf("/nInput the value of pos(must pos<S1.Len):"); scanf("%d",&pos); printf("/nInput the value of len:"); scanf("%d",&len); flag=StrDelete(s1,pos,len); if(flag=1) printf("/nThe operate is OK!"); else printf("/nThe operate is FALSE!"); printf("/nThe String is:"); output(s1); }