J
JKop
Here's two functions, a "const version" and a "non-const version":
char* GetFirstT(char* p)
{
for ( ; *p; ++p)
{
if ( *p == 't' ) return p;
}
return 0;
}
const char* GetFirstT(const char* p)
{
for ( ; *p; ++p)
{
if ( *p == 't' ) return p;
}
return 0;
}
signed main()
{
char the_alphabet[] = "abcdefghijklmnopqrstuvwxyz";
char* p_t = GetFirstT(the_alphabet);
}
See how I have to define two functions, is there any handy around that?
Would I have to do the following:
const char* GetFirstT(const char* p)
{
for ( ; *p; ++p)
{
if ( *p == 't' ) return p;
}
return 0;
}
char* GetFirstT(char* p)
{
return const_cast<char*>( GetFirstT(p) );
}
-JKop
char* GetFirstT(char* p)
{
for ( ; *p; ++p)
{
if ( *p == 't' ) return p;
}
return 0;
}
const char* GetFirstT(const char* p)
{
for ( ; *p; ++p)
{
if ( *p == 't' ) return p;
}
return 0;
}
signed main()
{
char the_alphabet[] = "abcdefghijklmnopqrstuvwxyz";
char* p_t = GetFirstT(the_alphabet);
}
See how I have to define two functions, is there any handy around that?
Would I have to do the following:
const char* GetFirstT(const char* p)
{
for ( ; *p; ++p)
{
if ( *p == 't' ) return p;
}
return 0;
}
char* GetFirstT(char* p)
{
return const_cast<char*>( GetFirstT(p) );
}
-JKop