Q:replacing strings without using inbuild functions.
OUTPUTE:
We are using gcc compiler and terminal to compile the code and ubuntu OS.
PROGRAM:
#include<stdio.h>
int strln1(char s1[]);
int strln2(char s2[]);
void strcpy1(char s1[],char s2[]);
int main()
{
char s1[30],s2[30];
int result1,result2;
printf("Enter the string s1");
scanf("%s",s1);
printf("Enter the string s2");
scanf("%s",s2);
printf("Your string s1 is %s",s1);
printf("\nYour string s2 is %s",s2);
result1=strln1(s1);
result2=strln2(s2);
printf("\nlength of string s1 is %d\n",result1);
printf("\nlength of string s2 is %d\n",result2);
strcpy1(s1,s2);
}
int strln1(char s1[])
{
int i,ln;
ln=0;
i=0;
while(s1[i]!='\0')
{
i++;
ln++;
}
return ln;
}
int strln2(char s2[])
{
int i,ln;
ln=0;
i=0;
while(s2[i]!='\0')
{
i++;
ln++;
}
return ln;
}
void strcpy1(char s1[],char s2[])
{
int z;
z=0;
for(z=0;s1[z]!='\0'||s2[z]!='\0';z++)
{
s1[z]=s2[z];
}
printf("s1=%s \nand s2=%s\n",s1,s2);
}
OUTPUTE:
uledvenza Sarah Thomas https://wakelet.com/wake/4XqNppNH0NI7Dy20lUcX3
ReplyDeletefiapicpolstech