I have an assignment to take the functions and use array subscripting and pointer arithmetic to write the functions.
int stringLength(const char* s);
char* stringCopy(char* s1, const char* s2);
char* stringConcatenate(char* s1, const char* s2);
and use the following tester driver:
but I have no idea where to start when it comes to writing the functions.
#include <iostream>
using namespace std;
// Implement the following function prototypes
int stringLength1( char *s );
int stringLength2(char *s );
char *stringCopy1( char *s1, const char *s2 );
char *stringCopy2( char *s1, const char *s2 );
char *stringCat1( char *s1, const char *s2 );
char *stringCat2( char *s1, const char *s2 );
// Use the following driver to test implementations:
int main()
{
char s1[ 100 ];
char* s2 = "education";
char* s3 = "school";
// Test stringLength functions
cout << "stringLength(" << s2 << "): "
<< stringLength1( s2 ) << endl;
cout << "stringLength(" << s3 << "): "
<< stringLength2( s3 ) << endl;
// Test stringCopy functions
cout << "stringCopy1(s1, " << s2 << "): "
<< stringCopy1( s1, s2 ) << endl;
cout << "stringCopy2(s1, " << s3 << "): "
<< stringCopy2( s1, s3 ) << endl;
// Test stringCat functions
cout << "stringCat1(s1, " << s2 << "): "
<< stringCat1( s1, s2 ) << endl;
cout << "stringCat2(s1, " << s3 << "): "
<< stringCat2( s1, s3 ) << endl;
system("pause");
return 0; // indicates successful termination
} // end main