strcpy() in C
0 1041
The strcpy() function in C helps to copy one string into another. It's like duplicating a string.
When you want to copy a message from one place to another, strcpy() comes in handy. It's found in the library, which provides tools to handle text.
Syntax of strcpy()
char *strcpy(char *destination, const char *source);destination: It's where you want to put the copied string. source: It's the string you want to copy from. Example of strcpy():
// program for strcpy()Output:
#include<stdio.h>
#include<string.h>
int main() {
char originalMessage[] = "Hello, friend!";
char copiedMessage[20]; // We need a place to store the copied message.
strcpy(copiedMessage, originalMessage); // Making a copy.
printf("Original Message: %s\n", originalMessage);
printf("Copied Message: %s\n", copiedMessage);
return 0;
Original Message: Hello, friend!
Copied Message: Hello, friend!
Advantages of strcpy() Function
Simplicity: strcpy() makes copying strings easy. It's like using a photocopier. Efficiency: It's built to work fast and smoothly, handling copying tasks efficiently. Compatibility: strcpy() is a standard tool, meaning it works the same across different systems and computers. Versatility: It can copy strings of any length, from short messages to long paragraphs. Return Value: The strcpy() function provides a pointer pointing to the destination string after the copy operation. It's like a note telling you where the copy is stored.
Share:




Comments
Waiting for your comments