Hi there. That's my first thread here. Maybe my english level is not good as yours coz i'm from Spain xD First of all, I have a constant string which has a thousand of chars, with no empty positions, only characters. And I have to find repetitions of 6-letter and 7-letter words. I've tried it all, but I can't find the way to do that. Anyone can help me please? Suppose that we have 2 initial vectors that contain the 6 or 7 letters.

Thank you in advance ;)

Hello.
A simple way to do it would be

$text = ???;
$text_array = strtok($text,' '); // Splits up all text by spaces
foreach($text_array as $values) // loops through every word 1 by 1
{
    $length = strlen($values); // calculate length of every single string
    if($length == 6 || $length == 7)
    {
        //TODO Add code handling for the words here
    }
}

I hope it helps

commented: First: your code is in PHP; Second: your code is wrong on the use of strtok. -3

here is the function which serves your purpose
int string_pat_find(char *string1,char *patten);

it take 2 arguments:

1st the char string
2nd the string to be found within and retuns the count occruance.

Code attached below:

#include<stdio.h>
#include<string.h>

int string_pat_find(char *string1,char *patten);
int main()
{
	char string1[1000]="abcapplesarriveataplacethenifounditappleajajajajajajajajajaj";
	char *letter[]={"apple","arrive","aj"};
	int count;
	int no_of_words=3;
	int i;
	for(i=0;i<no_of_words;i++)
	{
		count=string_pat_find(string1,letter[i]);
		printf("Count for %s is %d\n",letter[i],count);
	}
		
return 0;
}

int string_pat_find(char *string1,char *patten)
{
  char *temp;
  int count=0;
  while(string1!=NULL)
   {
    temp=strstr(string1,patten);
    if(temp==NULL)return count;
    string1=temp+1;
    count++;
   }
return count;
}
commented: Dont give out the codes,Try to make them learn,please... -1

Thank you for your answers, I'll check'em right now ^^,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.