فکر نمی کنید کدهای بالا اگه اینجوری نوشته بشه بهتره(منظورم به صورت LeftToRight هست)
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>//for use function malloc
main()
{
char *string,*string2;
char *ch;
int count=0,i,x=0,k;
//************ memory allocate ************
string=(char *) malloc (sizeof(char)*30);
string2=(char *) malloc (sizeof(char)*20);
ch=(char *) malloc (sizeof(char)*20);
if (!ch || !string2 || !string ) {
printf("Memory not allocated");
getch();
exit(0);
}
clrscr();
printf("Enter a statement:\n");
gets(string);
printf("\nEnter a word for searching in the statment:\n");
gets(ch);
x=strlen(string);
i=0;
while(*(string))
{
k=0;
while((*(string)!=' ') && *(string))
{
*(string2+k)=*(string++);
k++;
}
*(string2+k)='\0';
if(!strcmp(string2,ch))
count++;
string++;
}
printf("the itereation of word %s in this statement is %d",ch,count);
getch();
}
برای این کار یک [/code] بذارید آخر کد و یه [code] هم بذارید اول کد