Lab 8: C String Functions

We have been studying C string functions, and in class we reviewed these:

  strlen, strcpy, strncpy, strchr,strrchr, strstr, strcmp, strcat

This week you will write your own version of some of these string functions.

Important:

Specifically at each stage you will implement one of the following string functions:   strncpy, strchr, strrchr.   For each stage you need to prompt for and accept a string from the user, which will then be sent to a function.  All of this code is provided for you, however you will need to uncomment stages 2 and 3 within main() once you get to them.

Stage 1: strncpy (1 Point)

Provide the return type and parameters for function mystrncpy so that you copy n characters into the destination array.

Function mystrncpy does not return anything, and as parameters accepts the destination string, the source string, and the number of characters to be copied.

Stage 2: strchr (1 Point)

Provide the return type and parameters for function mystrchr so that you find the first occurrence of a character within a string.  Be sure to uncomment this section within main().

Function mystrchr returns the address of the character found, and as parameters accepts the the source string, and the character to be found.

Stage 3: strrchr (Extra Credit 1 Point)

Provide the return type and parameters for function mystrrchr so that you find the last occurrence of a character within a string.  Be sure to uncomment this section within main().

Function mystrrchr returns the address of the character found, and as parameters accepts the the source string, and the character to be found.