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\n", newStr);//print newStr value
 return 0;
}
Output:
Hello friend!
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.