program to copy the string without using strcmp funtion by using pointer.
In this program, we will now copy the string without using strcmp function by using pointer by taking input form the user.
#include<stdio.h>
#include<conio.h>
int copy(char *s2,char *s1);
void main()
{
char str1[50],str2[50];
printf("enter the string:-");
gets(str1);
copy(str2,str1);
printf("\n first string of str1 is :-%s",str1);
printf("\n second string of str2 is:- %s",str2);
getch();
}
int copy(char *s2,char *s1)
{
while(*s1!='\0'){
*s2=*s1;
s1++;
s2++;
}
s2='\0';
}
#include<conio.h>
int copy(char *s2,char *s1);
void main()
{
char str1[50],str2[50];
printf("enter the string:-");
gets(str1);
copy(str2,str1);
printf("\n first string of str1 is :-%s",str1);
printf("\n second string of str2 is:- %s",str2);
getch();
}
int copy(char *s2,char *s1)
{
while(*s1!='\0'){
*s2=*s1;
s1++;
s2++;
}
s2='\0';
}
output:-
For more c-programming:-
1.

No comments:
Post a Comment