copy string in c
#include <stdio.h>
#include <string.h>
int main() {
char source[] = "Hello, World!"; // Step 1: Declare and initialize the source string
char destination[20]; // Step 2: Declare the destination string with enough space
strcpy(destination, source); // Step 3: Use strcpy function to copy the source string to destination
printf("Source: %s\n", source); // Step 4: Print the source string
printf("Destination: %s\n", destination); // Step 5: Print the copied string (destination)
return 0; // Step 6: Return 0 to indicate successful execution
}
Note: Make sure that the destination array has enough space to accommodate the source string, including the null terminator. In this example, the destination array has a size of 20, which is sufficient for the "Hello, World!" string. Adjust the size according to the length of the strings you are working with.