#include
#include
void newstrcpy(char *,char *); /*Function declaration */
void newstrcat(char *,char *);
void main()
{
char str1[30],str2[20],temp[90];
int i=0;
clrscr();
printf(" enter the first string\n");
gets(str1);
printf("\n enter the second string\n");
gets(str2);
while(str1[i])
{
temp[i]=str1[i];
i++;
}
temp[i]='\0';
newstrcpy(str1,str2);
printf("copied string is \n%s \n %s",str1,str2);
newstrcat(temp,str2);
printf("\n the strings after cancantation: \nstring1: %s\nstring2:%s",temp,str2);
getch();
}
/* Function to copy 2 strings */
void newstrcpy(char *p,char *q)
{
while(*q)
{
*p=*q;
p++;
q++;
}
*p='\0';
}
/*Function to cancancate string */
void newstrcat(char *p,char *q)
{
while(*p)
{
p++;
}
while(*q)
{
*p=*q;
p++;
q++;
}
*p='\0';
}
No comments:
Post a Comment