Вы находитесь на странице: 1из 2

2.

write and demonstrate the following C functions:


a. newstrcpy that does the same job as strcpy
b. newstrcat that does the same job as strcat
without using any library functions.

PROGRAM

#include<stdio.h>
#include<conio.h>

void newcopy(char des[],char sor[])


{
int i;
for(i=0;sor[i]!='\0';i++)
des[i]=sor[i];
des[i]='\0';
}

void newcat(char des[],char sor[])


{
int i,j;
for(i=0;des[i]!=0;i++);
for(j=0;sor[j]!=0;i++,j++)
des[i]=sor[j];
des[i]='\0';
}

void main()
{
char a[1000],b[1000],cpy1[1000],cpy2[1000];
clrscr();
printf("\nEnter two strings..\n");
gets(a);
gets(b);
clrscr();

printf("\nCopy Function\n");
newcopy(cpy1,a);
newcopy(cpy2,b);
printf("\n\na=%s\nb=%s\ncpy1=%s\ncpy2=%s",a,b,cpy1,cpy2");

printf("\nConcatenation Function\n");
newcat(a,b);
getch();
printf("\n\na=%s\nb=%s\ncpy1=%s\ncpy2=%s",a,b,cpy1,cpy2);
getch();
}

OUTPUT

Enter two strings..


Comp
Science

Copy Function
a= Comp
b= Science
cpy1= Comp
cpy2= Science

Concatenation Function
a= Comp Science
b= Science
cpy1= Comp
cpy2= Science

Вам также может понравиться