一篇有关C的问题的文章,请帮忙啊!!十万火急!!!!!!!

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

#include"c1.c"

#include"c4-1.c"

#include"c2.c"

int String_Replace(SString S,SString T,SString V)/*将串S中所有子串T替换为V,并返回置换次数*/

{ int n,i,j,k,l;

for(n=0,i=0;i<=S.len-T.len;i++)

{

for(j=i,k=0;T.ch[k]&&S.ch[j]==T.ch[k];j++,k++);

if(k>=T.len) /*找到了与T匹配的子串:分三种情况处理*/

{

if(T.len==V.len)

for(l=0;l<=T.len-1;l++) /*新子串长度与原子串相同时:直接替换*/

S.ch[i+l]=V.ch[l];

else if(T.len<V.len) /*新子串长度大于原子串时:先将后部右移*/

{

for(l=S.len-1;l>=i+T.len-1;l--)

S.ch[l+V.len-T.len]=S.ch[l];

for(l=0;l<=V.len-1;l++)

S.ch[i+l]=V.ch[l];

}

else

{

for(l=i+V.len;l<=S.len+V.len-T.len;l++)

S.ch[l]=S.ch[l-V.len+T.len];

for(l=1;l<=V.len;l++)

S.ch[i+l-1]=V.ch[l];

}

S.len=S.len -T.len +V.len;

i+=V.len;n++;

}/*if*/

}/*for*/

return n;

}

main()

{SString s,t,v;

int n=0;

gets(s.ch);

s.len=StrLength(s);

gets(t.ch);

t.len=StrLength(t);

gets(v.ch);

v.len=StrLength(v);

n=String_Replace(s,t,v);

printf("%d",n);

puts(s.ch);

}

为什么int String_Replace(SString S,SString T,SString V)会没有执行就跨过了啊?

这是C1.C

#include<string.h>

#include<ctype.h>

#include<malloc.h>

#include<limits.h>

#include<stdio.h>

#include<stdlib.h>

#include<io.h>

#include<math.h>

#include<process.h>

#define TRUE 1

#define FALSE 0

#define OK 1

#define ERROR 0

#define INFEASIBLE -1

/* #define OVERFLOW -2 因为在math.h中已定义OVERFLOW的值为3,故去掉此行 */

typedef int Status; /* Status是函数的类型,其值是函数结果状态代码,如OK等 */

typedef int Boolean; /* Boolean是布尔类型,其值是TRUE或FALSE */

这是c4-4.c

/* c4-1.h 串的定长顺序存储结构 */

#define MAXLEN 20

typedef struct

{

char *ch; /* 存储空间基址 */

int len; /* 当前长度 */

}HString;

typedef struct

{

char ch[MAXLEN];

int len;

}SString;

这是c2.c

int StrLength(SString s)

{int i,n=0;

for(i=0;s.ch[i]!='\0';i++)

n++;

return(n);

}

大虾来帮一下忙啊!求救啊!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航