#include <stdio.h>
int main ()
{
	FILE *f;
	char VorodiStr[21];
	char *Kalame, ch;
	int i, FilePos, Count=0;
	printf ("Kalame ra vared konid : ");
	gets(VorodiStr);
	f = fopen("d:\\109TextFile.txt", "rt");
	if (f == NULL)
	{
		printf("File mojod nist");
		exit(0);
	}
	//araye be tule VorodiStr, 1 be khatere mahale gharar giri NULL entahaye str ast.
	Kalame = (char*)malloc(sizeof(char) * (strlen(VorodiStr) + 1));
	FilePos = 0;
	fseek(f, FilePos, SEEK_SET);
	i = 0;
	do {
		ch = fgetc(f);
		if (feof(f)) 
            break ;
		Kalame[i] = ch;
		i++;
		if (i == strlen(VorodiStr))
		{
			Kalame[i] = 0; //NULL
			if (strcmp(Kalame, VorodiStr) == 0)
				Count++;
			i = 0;
			FilePos++;
			fseek(f, FilePos, SEEK_SET);
		}
	}while (1);
	free(Kalame);
	printf ("\nTedade kalameye '%s' = %d\n", VorodiStr, Count);
	fclose(f);
	getch();
}

