#include <iostream>
#include <fstream>
#include <assert.h>
#include <map>
using namespace std;
int stupidKmp(const char* dest, const char* src, int pos)
{
int i=pos;
int j=0;
while(dest[i+j] && src[j])
{
if(dest[i+j]==src[j])
{
j++;
}
else
{
i++;
j=0;
}
}
if(src[j]==' ')
{
return i;
}
else
{
return -1;
}
}
int main()
{
map<int, int>mymap;
char src[]="abc";
int H=1;
ifstream readfile("./find.cpp",ios::in);
ofstream write;
write.open("./newfind.cpp");
string line;
if(! readfile)
{
assert(false);//fail open
}
while(! readfile.eof())
{
getline(readfile,line);
write<<line.c_str()<<endl;
int V=stupidKmp(line.c_str(),src,0);
if(V != -1)
{
mymap.insert(make_pair(H,V));
}
H++;
}
readfile.close();
write.close();
for(map<int ,int>::iterator iter=mymap.begin(); iter!=mymap.end(); iter++)
{
int first = iter->first;
int second=iter->second;
cout<< "row:"<<first<<" "<<"col:"<<second<<endl;
}
return 0;
}
find.cpp
aasssdafaabcdfadfaffs
dfafefaefaabcsdfefas
afefaseascabcasefwe
aerfawefasabefae
aeertawefabcasefawe
aererawfaabcwf3
aefe3faaabcwfwe
abc