串子系统
#include "stdio.h"
#define MAXSTIZE 100
typedef struct
{
cgar ch[MAXSIZE];
int Len;
}String;
int StrLength(String *S)
{
int i=0;
while(S->ch[i]!='\0')
i++;
S->Len=i;
return (S->Len);
}
void CreatStr(Strng *S)
{
gets(S->ch);
S->Len+StrLength(S);
}
int j;
if(pos<1 || pos>S->Len || len<1 || len>S->Len-pos+1)
{
Sub->Len=0;
printf("参数错误!\n");
return 0;
}
else
{
for(j=0;j<len;j++)
Sub->ch[j]=S->ch[pos+j-1];
Sub->ch[j]='\0';
Sub->Len=len;
return 1;
}
}
int StrIndex(String *S,String *T)
{
int i+0,j=0,k;
while(i<S->Len && j<T->Len)
{
if(S->ch[i]==T->ch[j])
{
i++;
j++;
}
else
{
i=i-j+1;
j=0;
}
}
if(j>=T->Len)
k=i-T->Len+1;
else
k=-1;
return k;
}
int StrCompare(String *S1,String *S2)
{
int i=0,flag=0;
while(S1->ch[i]!='\0'&&S2->ch[i]!='\0')
{ if(S1->ch[i]!=S2->ch[i])
{ flag=1;break; }
else
i++;
}
if(flag==0 && S1->Len==S2->Len)
return 0;
else
return S1->ch[i]-S2->ch[i];
}