- #1
chiurox
- 35
- 0
Homework Statement
Hi, so I have this assignment, more like a project. There are many parts to it.
Say there is a C String: "this does not match hi bartay"
And I have a Key: "my secret"
I need to match the key to a segment in C String that has exactly the same word lengths. In this case, "my secret" would match "hi bartay"
The Attempt at a Solution
So first I'm grabbing out of the C String the first same number of words as in the Key: "this does"
Then I'm comparing the length of the first word in the C String with the first word in my Key. This won't match, so then it grabs "does not" etc etc...
//storing the number of letters in each word of key
int letterCounter=0;
int pos=0;
for (int k=0; key[k]!='\0'; k++)
{
if(key[k]!=' ')
letterCounter++;
else
{
keyNumLetters[pos]=letterCounter;
pos++;
letterCounter=0;
}
}
//storing the number of letters in each word of C String
int letterCounter2=0;
for (int m=0; ctring[m] != '\0'; m++)
{
if(ctring[m] != ' ')
letterCounter2++;
else
{
ctring[pos2] = letterCounter2;
pos2++;
letterCounter2=0;
}
}
Is this code right? How do I compare the arrays and if they are not the same, how do I get to grab the next words?