#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
const int MAX_LONG=40;
const int TRUE=1;
const int FALSE=0;
void result_write( int , char* , char* );
int main()
{
char x[MAX_LONG] = "His teaching method is very good.";
char y[MAX_LONG]={0,};
cout << "현재의 문자열은 "<< x << "입니다.\n 검색하려는 문자열을 입력해주세요. \n >>>";
cin >> y;
int where_word=0;
while (0!=x[where_word])
{
int such_word=0;
while (x[where_word+such_word]==y[such_word] && 0!=y[such_word])
++such_word;
if (such_word>=strlen(y))
{
result_write( where_word , x , y );
return TRUE;
}
++where_word;
}
result_write( -1 , x , y );
return FALSE;
}
void result_write(int where, char *original, char *such_word)
{
ofstream outputFile("result.out");
outputFile << "자료 -> " << original << "\n찾을 문자열 -> " << such_word << "\n";
if (-1==where)
outputFile << "Not found!";
else
outputFile << "first found -> " << where;
outputFile.close();
}