code for copying two strings with out strcpy() function.

Answer Posted / reachhary

well, we could also have a string accepted at run time by
use of scanf.

To take care of such cases.

char *mystrcpy(char src[])
{
char *dest = NULL;
int indx = 0, len = 0;
if (!src) return dest;
len = strlen(src);
dest = (char *)malloc(sizeof(char) * len + 1);
while (; src[indx] ; dest[indx++]=src[indx]);
dest[indx]='\0'
return (dest)
}
Please do update if any one finds any issue with the code
segment - in terms of any error or any optimisation

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When can a far pointer be used?

586


#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }

625


What is the use of typedef in structure in c?

542


Is c# a good language?

605


Explain what is the benefit of using const for declaring constants?

613






write a programming in c to find the sum of all elements in an array through function.

1705


Why is c called "mother" language?

855


Can you write the algorithm for Queue?

1550


How can you convert integers to binary or hexadecimal?

614


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9654


When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.

1529


What does %c mean in c?

647


How can you return multiple values from a function?

628


how to find anagram without using string functions using only loops in c programming

2715


How can I do graphics in c?

589