I have the following code for a dictionary.
void Dictionary::translate(char out_s[], const char s[])
{
for (int i=0;i
Not "for iso" (perhaps read the entire error message...), but for ISO C++. The problem is that the scope of the i
variable is only the for
loop (since its definition is inside the initialization of the loop). Since it seems you want to use it outside the loop, declare it like so:
int i;
for (i = 0; i < foo; i++) {
// ...
}
do_safe_stuff_with(i); // valid
When you do e.g.
for (int i=0;i<numEntries;i++)
then the variable i
is local to the loop only, you can't really use it outside the loop.
If you want to use i
outside the loop, then you need to declare it outside the loop:
int i;
for (i=0;i<numEntries;i++)
i
is declared in the for
loop condition clause. it is not visible at the if
clause after for
loop.
try:
int i = 0;
for (;i<numEntries;i++)
{
if (strcmp(englishWord[i], s)==0)
break;
}
if (i<numEntries)