I am attempting to check string letters against another let of letters, checking the first letter in userword[k] against all the letters in letterstest[t] and if they match switching that matching letter of letterstest[t] with 0 so it cannot be matched again. Where I am confused on is inside the switch(){ and what exactly would work. Is there a case: what can switch the letters of the strings?
for (k = 0; k<wordsize; k++){
for(t=0; t<8, t++){
if (userword[k] != letterstest[t])
return 0;
if (userword[k] == letterstest[t]){
switch (letterstest[t]){
//unsure what case would work here
}
}
}
}
I think you’re misunderstanding what
switchis.switchis a selection structure, likeif/else. For example, these two code-snippets are (generally) equivalent:I’m not completely clear on what you’re trying to do, but when you write “if they match switching that matching letter of letterstest[t] with 0 so it cannot be matched again”, it sounds like you mean this:
Edited to add: O.K., I think I now understand what you’re trying to do:
userword[0]anduserword[wordsize-1]appears somewhere betweenletterstest[0]andletterstest[7].userword[0]anduserword[wordsize-1], then it must appear at least as many times betweenletterstest[0]andletterstest[7]. That is — a character betweenletterstest[0]andletterstest[7]can only count once.letterstest[0]andletterstest[7], as long as the final answer is correct; that is, you don’t need to preserve the contents ofletterstest.'\0'does not occur anywhere betweenuserword[0]anduserword[wordsize-1], so can be used as a “dummy” value meaning “not a match”.Is that correct?
If so, then you can write: