Question: Purpose: Use of POINTER ONLY notation with malloc() function usage. NO INDEX or SQUARE BRACKET USAGE! Passing pointers between functions Using characters and character pointers
Purpose:
Use of POINTER ONLY notation with malloc() function usage. NO INDEX or SQUARE BRACKET USAGE!
Passing pointers between functions
Using characters and character pointers
Description
Implement a C program that will read in two character strings and store them. Then count the number of characters in the string and display their size. Then malloc( ) enough space for both strings and combine them together.
void string_Size (char *): This function takes character pointer used for the string that was read in and will count the number of characters in a string.
int string_Compare (char *, char *): This function takes two character pointers and checks to see if the two strings are identical. The int return type will be used to communicate if the strings are identical = 1 means identical, -1 means not identical.
int string_Combine(char *, int size1, char *, int size2): This function will take the character pointer for both strings and combine the two into a new malloc( ) string space.
Sample output
$ ./a.out
Enter String 1: hello world
Enter String 2: hello world
String 1 length is 11
String 2 length is 11
The strings are identical
The strings combined are: hello world hello world
Enter String 1: fred
Enter String 2: sue
String 1 length is 4
String 2 length is 3
The strings are not identical
The strings combined are: fred sue
Enter String 1: I love
Enter String 2: CS1050
String 1 length is 6
String 2 length is 6
The strings are not identical
The strings combined are: I love CS1050
Enter String 1: exit
PROGRAM TERMINATED
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
