C Program to Copy string without using strcpy function

here we copy by creating our own function which uses pointers.

#include<stdio.h>

void copy_string(char*, char*);

main()

{

char source[100], target[100];

printf(“Enter source string\n“);

gets(source);

copy_string(target, source);

printf(“Target string is \”%s\”\n“, target);

return 0;

}

void copy_string(char *target, char *source)

{

while(*source)

{

*target = *source;

source++;

target++;

}

*target = ‘\0‘;

}

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*