Lab8

Home Up

 

 Lab1 ] Lab2 ] Lab3 ] lab4 ] lab5 ] lab6 ] Lab7 ] [ Lab8 ] Lab9 ] Lab10 ]

CP107  LAB 8

 

 

LAB 8A  OBJECTIVES LAB:

Use the array data structure as an argument to a function
Use an array to contain characters notation and with pointers
Use an array to contain a character string (terminated with a null character)
String manipulation

 

LAB ASSIGNMENT

 Starting with the given file, stringfunctions.cpp, student will be writing new function definitions for the 8 string functions listed below.

Starting with the sample program, stringfunctions.cpp, make the following modifications:

comment out # include <cstring>

Change the name of all 7 functions from slightly so you do not call the string runtime library functions.
Example: change strcpy to myStrcpy.
Do all of the problem using pointer notation. I have provided some of the functions with array notation. Convert them so that they use pointers.

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

char *strncpy( char *s1, const char *s2, size_t n );

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

char *strncat( char *s1, const char *s2, size_t n );

int strcmp( const char *s1, const char *s2 );

int strncmp( const char *s1, const char *s2, size_t n );

unsigned int strlen( const char *s );

  Test and debug your program to make sure that your functions work identical to the library functions. Submit your program as stringfunctions.cpp

 

 

Copyright (c) Yusuf Family Website 2001