C Program Code For Copying the String Without STRCPY Function, Custom Made StringCopy Function

Leave a Comment
 /* The following C  program is used to copy a string in another array without using string.h function, strcpy(). The program asks for the input from user & the value is copied in the 2nd variable then displayed to user. */

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void mystrcpy(char *d, char *s) 
//Function definition for string copy function
{
while(*s)
//While the source string is not encountered a NULL character
{
 *d=*s;
 s++;
 d++;
}
*d='\0';
}


int main()
{
  char s1[100];
  char s2[100];
  printf("\nEnter a string to copy: ");
  gets(s2);  
//User Input the string here
  mystrcpy(s1,s2);
  printf("\nThe Copied String is : ");
  puts(s2); 
//Copied string output shown here
  system("pause");
  return 0;
}


Screenshot:
C  Program Code For Copying the String Without STRCPY Function, Custom Made StringCopy Function

0 comments: