Tuesday, April 30, 2013

c Program to Copy one String to Another Without Using strcpy()

/* Program to Copy one String to Another Without Using strcpy() */
#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
char string1[20], string2[20];
int i;
printf("Enter the value of STRING1: \n");
gets(string1);
for(i=0; string1[i]!='\0'; i++)
string2[i]=string1[i];
string2[i]='\0';
printf("\nThe value of STRING2 is:\n");
puts(string2);
getch();
}

step 1:It reads  array of strings
step 2:loop condition checks for whether  the end of the string ie '\0'.If that reaches the end ,the
loop will stop otherwise the content of the string 1 will move to the string 2
puts(string2) print the string

No comments:

Post a Comment