The Program in C to Copy one string into another inputted by user is given below:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100], str2[100];
printf("Enter the first string: ");
scanf("%s", str1);
printf("Enter the second string: ");
scanf("%s", str2);
strcpy(str2, str1);
printf("The second string after copying: %s\n", str2);
return 0;
}
Output:
Enter the first string: hello
Enter the second string: whats up
The second string after copying: hello
Pro-Tips💡
The strcpy
function is used to copy the contents of the first string (str1
) into the second string (str2
).
The scanf
function is used to read the strings from the user.
The printf
function is used to display the second string after it has been copied.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.