int strcmp(const char *s,const char *t)
{
int i;
for (i = 0; s[i] == t[i]; i++)
if (s[i] == '\0')
return 0;
return s[i] - t[i];
}
and NOT
for (int i = 0; s[i] == t[i]; i++)
????
the compiler says obsolete binding...?
C++ programming?
in the for(int i=0 ...)
you want to use the i variable outside the scope (i is available only into the scope of for statement)
Do you use an old book to learn C++ ? or a book based on draft ?
Reply:If you define int i within a (for) loop you have to define it again in subsequent loops otherwise you will get the error.
So
int main()
{
for (int i = 0; i %26lt; 10; ++i )
;
for (i = 0; i %26lt; 10; ++i )
;
}
// is wrong
int main()
{
for (int i = 0; i %26lt; 10; ++i )
;
for (int i = 0; i %26lt; 10; ++i )
;
}
// is correct.
Reply:try declaring i out side the strcmp scope
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment