strcpy in C
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "C programming";
char str2[20];
// copying str1 to str2
strcpy(str2, str1);
puts(str2); // C programming
return 0;
}
strcpy in C
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "C programming";
char str2[20];
// copying str1 to str2
strcpy(str2, str1);
puts(str2); // C programming
return 0;
}
strcpy c implementation
#include <stdio.h>
// Function to implement strcpy() function
char* strcpy(char* destination, const char* source)
{
// return if no memory is allocated to the destination
if (destination == NULL)
return NULL;
// take a pointer pointing to the beginning of destination string
char *ptr = destination;
// copy the C-string pointed by source into the array
// pointed by destination
while (*source != '\0')
{
*destination = *source;
destination++;
source++;
}
// include the terminating null character
*destination = '\0';
// destination is returned by standard strcpy()
return ptr;
}
// Implement strcpy function in C
int main(void)
{
char source[] = "Techie Delight";
char destination[25];
printf("%s\n", strcpy(destination, source));
return 0;
}
strcpy implementation in c
while ((*destination++ = *source++) != '\0');
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us