Answer:
Following are the complete code to the given question:
#include <stdio.h>//header file
#include <string.h>//header file
#include <stdlib.h>//header file
int main()//main method
{
char userStr[100] = "";//defining a char array
char* newStr = NULL;//defining a char pointer
strcpy(userStr, "Hello friend!");//use strcpy method that holds char value
newStr = (char *)malloc(strlen(userStr));//defining a char variable that use malloc method
strcpy(newStr, userStr);//use strcpy method that holds newStr and userStr value
printf("%s\\", newStr);//print newStr value
return 0;
}
Output:
Hello friend!
Step-by-step explanation:
In this code inside the main method a char array "userStr" and a char type pointer variable "newStr" holds a value that is null, and inside this strcpy method is declared that holds value in the parameters.
In this, a malloc method is declared that uses the copy method to hold its value and print the newStr value.