if statement - C - not entering if even when he should -


i'm mad right now. need compare 1 string second, when chars second string can somehow create first string. example


foo1 = bill

foo2 = boril

foo2 can create foo1, because contains letters foo1.


so there's program:

secret = religion

lettersguessed = religonvpst

for(i = 0; < lensecret; i++){       for(l = 0; l < lenguessed; l++)         printf("a: %c, b: %c, c: %d\n", secret[i], lettersguessed[l], count);         if(secret[i] == lettersguessed[l]){             printf("hi\n");             count++;             break;         }         printf("c: %d\n", count); } 

but variable count stays @ 0. output console:

http://pastebin.com/yrhinlni

as can see right beginning, when secret[i] == lettersguessed[l] in if should return true(1), returns false(0). what's wrong this? why it's not working?

it's because don't have curly braces after second loop. if don't wrap block of code want iterate on curly braces, code before first semi-colon encountered executed. in case, second loop iterate on printf statement nothing else. variable l equal lenguessed when if statement executed , no letter first word matches last letter of second word, therefore count never incremented.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -