VC ++问题

来源:百度知道 编辑:UC知道 时间:2024/06/22 09:13:03
#include<stdio.h>
#include<stdlib.h>
#define MAXSTRLEN 255
#define ERROR 0
typedef unsigned char sstring[MAXSTRLEN+1];
int Index(sstring S,sstring T,int pos){
if(pos<1||pos>MAXSTRLEN+1) return ERROR;
int i,j;
i=pos;j=1;
while(S[i]&&T[j]){
if(S[i]==T[j]){i++;j++;}
i=i-j+2;j=1;
}
if(j>T[0]) return i-T[0];
else return 0;
}
void main()
{
sstring S[MAXSTRLEN+1],T[MAXSTRLEN+1];
int i,j,k;char ch;
while(S[i])
{
ch=getchar();
S[i]=ch;
i++;
}
while (T[j])
{
ch=getchar();
S[j]=ch;
j++;
}
scanf("%d",&k);
Index(S,T,k);
}
这个程序哪里错了,我在VC上运行,出现了错误

记得变量要初始化
#include<stdio.h>
#include<stdlib.h>

#define MAXSTRLEN 255
#define ERROR 0
typedef unsigned char sstring[MAXSTRLEN+1];
int Index(sstring S,sstring T,int pos){
if(pos<1||pos>MAXSTRLEN+1) return ERROR;
int i,j;
i=pos;j=1;
while(S[i]&&T[j]){
if(S[i]==T[j]){i++;j++;}
i=i-j+2;j=1;
}
if(j>T[0]) return i-T[0];
else return 0;
}
void main()
{
sstring S,T; //注意此处声明
int i=0, j=0,k; //i,j必须初始化
char ch;
while(S[i])
{
ch=getchar();
S[i]=ch;
i++;
}
while (T[j])
{
ch=getchar();
S[j]=ch;
j++;
}
scanf("%d",&k);
Index(S,T,k);
}

#include<stdio.h>
#include<stdlib.h>

#define MAXSTRLEN 255
#define ERROR 0
typedef unsigned char sstring[MAXSTRLEN+1];
int Index(sstring S,sstring T,int pos){
if(