Question: Write a C++ program that implements the following STDC Library string.h functions. size_t strlen(const char *__s); int strcmp(const char *__s1, const char *__s2); char* strcpy(char
Write a C++ program that implements the following STDC Library string.h functions.
size_t strlen(const char *__s); int strcmp(const char *__s1, const char *__s2); char* strcpy(char *__s1, const char *__s2); char* strcat(char *__s1, const char *__s2);
The size_t strlen(const char* __s) function returns the length of _s. Note: The length of a string excludes the terminating NULL character.
The int strcmp(const char* __s1, const char* __s2) function returns 0 if __s1 equals __s2; -1 if __s1 is lexicographically less than __s2; +1 if __s1 is lexicographically greater than __s2. Note: In the case of inequality, our return values of our strcmp() function differ from those in the STDC Library.
The char* strcpy(char* __s1, const char* __s2) function copies __s2 into __s1. The copy includes the NULL terminating character (i.e. __s1 must be NULL terminated). The function returns __s1.
The strcat(char *__s1, const char *__s2) functions concatenates the contents of __s2 onto __s1 beginning with the NULL character of __s1. Note: The concatenation includes the NULL character of __s2. The function returns __s1.
At minimum the main() function should prompt the user to enter two strings that are used as arguments to the string functions.
The STDC Library has functions that can be used
to process strings (i.e. null terminated arrays
of characters). You are required to write four
of t heSTDC Library functions: strlen(), strcpy(),
strcmp(), and strcat() functions.
To get the input, you can do:
char s1[512], s2[512]
prompt for string 1
cin >> s1
prompt for string 2
cin >> s2
s1 and s2 are passed to the functions you write.
The main() function should contain code that you
use to test your functions.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
