Sunday 6 October 2013

custom strcpy function in c to copy a string

#include<stdio.h>
#include<conio.h>
void mystrcpy(char *dest,const char*src)
{
while(*src)
{
 *dest=*src;
 src++;
 dest++;
}
*dest='\0';
}
int main()
{
  char str1[10]="Welcome";
  char str2[10];
  clrscr();
  printf("\nEnter a string: ");
  gets(str2);
  puts(str1);
  puts(str2);
  //stcpy(str1,str2); -- way to call library function
  mystrcpy(str1,str2);
  puts(str1);
  puts(str2);
  return 0;
}

No comments:

Post a Comment