#include "stdio.h"
#include "iostream.h"
#include "stdlib.h"
#include "string.h"
#define ERROR 0
#define OK 1
#define TURE 1
#define FAULSE 0
#define OVERFLOW -2
typedef struct string
{ char *st;
int length;
}String;
status stringassign(String &ST,char *cstring)
{ int i,j;
printf("Cstring= %s\n", cstring);
i=strlen(cstring);
printf("i=%d\n",i);
if(!i)
{ ST.st=NULL;ST.length=0; }
else
{
if(!(ST.st=(char *)malloc(i+1*sizeof(char))))
return OVERFLOW;
for(j=0;j<=i;j++)
ST.st[j]=cstring[j];
ST.length=i;
}
printf("Createstringsuccessfully!");
return OK;
}
int index(String ST,String Search,int cur)
{ int i,j;
i=cur;
j=0;
while(i<=ST.length&&j<Search.length)
{ if(ST.st[i]==Search.st[j])
{ ++i; ++j; }
else
{ ++i; j=0; }
}
if(j==Search.length)
{ printf("已经找到此串,串在第%d位\n",i-j);
return i-j; }
else
{ printf("没有此串! \n");
return -2; }
}
int main(int argc, char* argv[])
{
String Sstring;
int i=0,pos;
char Schar[100];
printf("请输入主串:\n");
getch Schar;
stringassign(Sstring &S1,Schar);
printf("请输入模式串: \n");
getch Schar;
stringassign(Sstring &S2.Schar)
pos=0;
int index(S1,S2,pos):
}
错误弹出来说的是
Compiling...
22.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\2222\22.cpp(15) : error C2146: syntax error : missing ';' before identifier 'stringassign'
C:\Program Files\Microsoft Visual Studio\MyProjects\2222\22.cpp(15) : error C2501: 'status' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\2222\22.cpp(15) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
22.obj - 1 error(s), 0 warning(s)