#include <iostream>
#include <fstream>
#include <string.h>
#include <conio.h>
using namespace std;
int main()
{
	fstream myfile;
	char VorodiStr[21];
	char *Kalame, ch, *NewStr;
	int i, FilePos, Count=0, Temp;
	cout << "Kalame ra vared konid : ";
	gets(VorodiStr);
	myfile.open("d:\\110TextFile.txt", ios::in | ios::out);
	if (!myfile.is_open())
	{
		cout << "File mojod nist";
		exit(0);
	}
	//araye be tule VorodiStr, 1 be khatere mahale gharar giri NULL entahaye str ast.
	Kalame = new char[ sizeof(char) * (strlen(VorodiStr) + 1) ];
	NewStr = new char[ sizeof(char) * (strlen(VorodiStr) + 1) ];
	for(i=0; i < strlen(VorodiStr); i++)
		NewStr[i] = '-';
	NewStr[i]=0; //NULL
	FilePos = 0;
	myfile.seekg(FilePos, ios::beg);
	i = 0;
	do {
		myfile.get(ch);
		if (myfile.eof()) 
            break ;
		Kalame[i] = ch;
		i++;
		if (i == strlen(VorodiStr))
		{
			Kalame[i] = 0; //NULL
			Temp = 0;
			if (strcmp(Kalame, VorodiStr) == 0)
			{
				myfile.seekg(FilePos, ios::beg);
				myfile.write(NewStr, strlen(NewStr));
				Count++;
			}
			i = 0;
			FilePos++;
			myfile.seekg(FilePos, ios::beg);
		}
	}while (1);
	delete[] Kalame;
	delete[] NewStr;
	cout << endl << "Tedade Jaygozini = " << Count << endl;
	myfile.close();
	getch();
}

