Write a program in C language to copy a string without using the library function.

#include<stdio.h>
#include<conio.h>
// function to copy a string
void strcopy(char s1[50], char s2[50])
{
int i=0;
while(s[1i]!='\0')
{
s2[i]=s1[i];
i++;
}
s2[i]='\0';
}
int main()
{
char str1[50],str2[50];
clrscr();
printf("Enter the source string\n");
gets(str1);
strcopy(str1,str2);
printf("Destination string is\n");
puts(str2);
getch();
}

Output:
Enter the source string
Mukesh
Destination string is
Mukesh
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: