Can anyone show me how to do this problem

C-Style String Manipulation Program

Write two versions of each of the following functions. The first version (1) should use array subscripting. The second version (2) should use pointers and pointer arithmetic. Place the functions in the same file as main and following the main function:

int stringLength(const char* s);

Determines the length of string s. The number of characters preceding the terminating null character is returned.

char* stringCopy(char* s1, const char* s2);

Copies the string s2 into the character array s1. The value of s1 is returned.

char* stringConcatenate(char* s1, const char* s2);

Appends a copy of string s2 to string s1. The first character of s2 overwrites the terminating null character of s1. The value of s1 is returned.

NOTE: Your program should not include <cstring> or use any functions from the cstring library.

Sample Output:

stringLength1(education): 9
stringLength2(school): 6
stringCopy1(s1, education): education
stringCopy2(s1, school): school
stringCat1(s1, education): schooleducation
stringCat2(s1, school): schooleducationschool




Use the following test driver to test your implementations of 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
closed account (Dy7SLyTq)
well we cant write code for you, but google a pointer tutorial
I need the solution please
We're not going to do your homework for you.
Make an attempt. We'll try to help if you run into specific problems.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
Topic archived. No new replies allowed.