#include<stdio.h>
#include <iostream>
using namespace std;
int main()
{
FILE*f=fopen("C:\\bb.txt","r");
if(NULL==f)
{ return -1;//要返回错误代码
}
char buf[]={512};
int r=fread(buf,1,256,f);
int s=0,count=0;
while(r>0)
{
char *pos;
if(pos=strstr(buf,"中国"));
{
printf("find at pos %d\n",s+(pos-buf));
s+=r;
}
return 0;
}
}
这个pos的位置为什么是s+(pos-buf))?
pos是在BUF中的指针是第几个,为什么要加?
懂的朋友画图表示下,实在不太理解这个定位!
和我说的不一样啊,pos是相对buf的地址啊!