Description
Problem 1
Write a program that implements four of the string library functions using pointers: strcopy (string copy), strconcat (string concatenate), strcomp (string compare), and strlength (string length). First, the program will ask the user to enter two strings with a maximum of 20 characters each. The program will then output the length of each string. Then, it will output which string comes first alphabetically. The program will then add string 1 to string 2 and output the two strings. Finally, the program will copy string 1 into string 2 and print the two strings again.
Your program should:
- Using the strlength function, calculate and print out the length of each string.
- Using the strcomp function, print out which string comes first alphabetically.
- If the strings are the same your program should print out: “The two strings are the same.”
- If string 1 comes first alphabetically your program should print out: “String 1 comes before string 2 alphabetically.”
- If string 2 comes first alphabetically your program should print out: “String 2 comes before string 1 alphabetically.”
- Using the strconcat function, add string 1 to the end of string 2 and print out string 1 and 2
- Using the strcopy function, copy string 1 into string 2 and print out string 1 and 2
The program should function as follows (items underlined are to be entered by the user):
Please enter the first string: jackhammer
Please enter the second string: Jacky
The length of string 1 is: 10
The length of string 2 is: 5
String 1 comes before string 2 alphabetically.
String 1 after concatenation: jackhammer
String 2 after concatenation: Jackyjackhammer
String 1 after copying: jackhammer
String 2 after copying: jackhammer
Your program should implement and use the following functions:
- strlength: This function will take as a parameter a character pointer to a string. It will return the length of the string, not including the null terminator.
- strcopy: This function should take as parameters two character pointers to two strings (a destination string and a source string in that order). Then it will copy the source string into the destination string, including the null terminator. It will then return a pointer to the beginning of the destination string.
- strconcat: This function should take as parameters two character pointers to two strings (a destination string and a source string in that order). Then it will add the source string to the end of the destination string. It will then return a pointer to the beginning of the destination string.
- strcomp: This function will take as parameters two character pointers to two strings (string 1 and string 2 in that order). The function then compares the two strings and if string 1 comes first alphabetically it returns 1. If the string 2 comes first alphabetically then it returns -1. If the strings are the same, then the function returns 0. The function should compare the two strings one character at a time and return the appropriate value as soon as a difference is noticed between the strings.




