#include
#define MAXSIZE 100
typedef char ElemType;
typedef struct
{
ElemType *ch;
int length;
}HString;
void print(HString a);
void scan(HString v);
void Replace(HString S,HString S1,HString S2);
void main()
{
HString a,b,c;
printf("\nS=");
scan(a);
printf("\nS1=");
scan(b);
printf("\nS2=");
scan(c);
Replace(a,b,c);
print(a);
}
void scan(HString v)
{
int i=1;
ElemType c;
v.ch=new ElemType[MAXSIZE];
v.length=0;
c=getchar();
if(c!='$')
{
v.ch[i]=c;
i++;
v.length++;
}
}
void print(HString a)
{
int i;
printf("最后结果为:");
for(i=1;i<a.length;i++)
{
printf("%c",a.ch[i]);
}
}
void Replace(HString S,HString S1,HString S2)
{
int i,j,k;
for(i=1,j=1;i<S.length;i++)
{
while(S.ch[j]==S1.ch[i]&&j<S1.length)
{
i++;
j++;
}
if(j==S1.length)
{
for(k=1;k<S1.length;k++)
{
S.ch[i]=S2.ch[k];
i++;
}
}
}
}
求指点哪里有错误,以及更正方法,新手经常踩雷。。
调试结果如下:
--------------------Configuration: 自测题串 - Win32 Debug--------------------
Compiling...
自测题串.c
D:\c语言\自测题串.c(34) : error C2065: 'new' : undeclared identifier
D:\c语言\自测题串.c(34) : warning C4047: '=' : 'char *' differs in levels of indirection from 'int '
D:\c语言\自测题串.c(34) : error C2146: syntax error : missing ';' before identifier 'ElemType'
D:\c语言\自测题串.c(34) : error C2275: 'ElemType' : illegal use of this type as an expression
D:\c语言\自测题串.c(3) : see declaration of 'ElemType'
Error executing cl.exe.
自测题串.obj - 3 error(s), 1 warning(s)