#include <stdio.h>
// Function to copy a string from src to dest
void my_strcpy(char *dest, const char *src) {
while (*src != '\0') {
*dest = *src;
dest++;
src++;
}
*dest = '\0'; // Null terminate the destination string
}
int main() {
char src[100], dest[100];
// Taking user input for source string
printf("Enter a string to copy: ");
fgets(src, sizeof(src), stdin);
// Removing trailing newline from the input (if present)
int len = 0;
while (src[len] != '\0') {
if (src[len] == '\n') {
src[len] = '\0';
}
len++;
}
// Copying the source string to destination using my_strcpy
my_strcpy(dest, src);
// Outputting the copied string (in destination)
printf("Copied string: %s\n", dest);
return 0;
}
Editor is loading...