C Program to Copy string without using strcpy function

here we copy string 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‘;

}

 

This entry was posted in C,C++ Programing, Freshers, Programing, Technical Interviews Questions and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>