# Thread: String testing

1. ## String testing

Hello, im trying to design a function that takes in a string, and test it for having

" The first 1/3 (rounding down) of the word's letters is repeated elsewhere in the word. e.g. abracadabra"

I understand the logic of looping through the array, and finding matches, but have been un-able to create a working test that does the above task correctly.

and help would be greatly appreciated.

thanks
nailz

2. What have you tried so far? Post some code. A pseudo-code is
Code:
```find 1/3 of the word and store them in a string called KEY;
for each letter in the word try to match one of the letters in KEY;
If a letter matches, remove it from the KEY and procede;
Loop, until there is no letter in KEY or in the word;```

3. Originally Posted by C_ntua
What have you tried so far? Post some code. A pseudo-code is
Code:
```find 1/3 of the word and store them in a string called KEY;
for each letter in the word try to match one of the letters in KEY;
If a letter matches, remove it from the KEY and procede;
Loop, until there is no letter in KEY or in the word;```
I understand what you mean- i understand the basic logic that I need to do here, but actually writing it into code is proving to be a challenge

this is my current stab at it, i apologize for the sloppy-ness.... it has gone under many revisions

int Test4(char test4[])
{
char firstT[35];
int wordLength = strlen(test4);
int ndxPos, ndx2Pos, match, counter;
int iteration = wordLength / 3;
match = 0;
counter = 0;

for (ndxPos = 0; ndxPos < wordLength / 3; ndxPos++) {
firstT[ndxPos] = test4[ndxPos];
}
for (ndxPos = iteration; ndxPos < strlen(test4); ndxPos++, counter++) {
if (firstT[counter] == test4[iteration + counter]) {
for (ndx2Pos = ndxPos; ndx2Pos < iteration + 3; ndx2Pos++) {
if (firstT[counter] == test4[ndxPos + counter]) {
match++;
if (wordLength <= 5) {
if (match - 1 == (wordLength + 2) / 3) {
printf("%s is in category 4.\n", test4);
return 1;
}
}
else if (match == (wordLength + 2) / 3) {
printf("%s is in category 4.\n", test4);
return 1;
}
}
counter++;
}
}
}
return 0;
}

4. bump

Popular pages Recent additions