error: `Sleep' undeclared (first use this function)
#include <string.h> #include <Tchar.h>
#include <fstream>
#include <dos.h>
//using namespace std;
int num=0;//统计匹配次数
int last(char *p, char c) { //找到c在p中最后匹配的位置,没有就返回-1
int length = strlen(p), count = 0;
char *pp = p + length -1;
while (pp >= p)
{
if (*pp == c)
{
return length - count - 1;
}
pp--;
count++;
}
return -1;
}
int min(int a, int b){
return (a <= b) ? a : b;
}
int BM_index(char *T, char *p) { //模式匹配
int n = strlen(T);
int m = strlen(p);
int i = m-1, j = m-1;
while (i <= n-1)
{
if (T[i]==p[j])
{
if (j==0)
{
return i;
}
else
i--, j--;
}
else {
i = i + m - min(j, 1+last(p, T[i]) ); //往后跳,取决于最后一次匹配的字符的位置
j = m - 1;
}
num++;
}
return -1;
}
//int _tmain(int argc, _TCHAR* argv[])
int main(int argc, char* argv[])
{
FILE *fp;//读取文本
if((fp=fopen("test.txt","a"))==NULL)
{
printf("File open failed!\n");
exit(0);
}
char t[]={""};
fgets(t,1024,fp);
fclose(fp);
//char *p = "woainizz!izzzzzz--zzzzut";
//int a = BM_index(p, "zzzzut"); //结果18,没有问题
int a = BM_index(t,"zzzzut"); //结果18,没有问题
Sleep(5000);
printf("%d",a);
return 0;
}
编译出现error: `Sleep' undeclared (first use this function)错误,怎么回事啊啊?