Need help with a code that I have been working on all day. if someone could help me, would really appreciate it. The problem is that it keeps telling me that i is not defined.
#include <iostream>
#include <cstring> // for std::strcpy
// note: use a different name; <cstring> may (is allowed to)
// expose strcat as a member of the global namespace
void my_strcat( char dest[], constchar srce[] )
{
unsignedint i;
for( i = 0; dest[i]; ++i ); //strlen(dest);
std::strcpy( dest+i, srce );
}
void my_strcat2( char dest[], constchar srce[] )
{
while( *dest ) ++dest ; // get to the null character in dest
// while( *dest++ == *srce++ ) ; // copy chars in srce till a null character is copiedwhile( ( *dest++ = *srce++ ) ) ; // copy chars in srce till a null character is copied
}
int main()
{
// make sure that the destination array is large enough to cat to
char dest[1024] = "Pass it to the mirror. ";
constchar srce[] = "Hit it twice pass it back.";
std::cout << "before my_strcat: " << dest << '\n' ;
my_strcat( dest, srce );
std::cout << " after my_strcat: " << dest << '\n' ;
constchar srce2[] = " and so on and so forth..." ;
// my_strcat( dest, srce2 );
my_strcat2( dest, srce2 );
std::cout << "after my_strcat2: " << dest << '\n' ;
}