/* WAP to accept two strings and concatenate them without using string functions */
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[20],str2[20],ch;
int i,j,len=0;
clrscr();
printf("Enter 1st string : ");
scanf("%s",&str1);
printf("Enter 2nd string : ");
scanf("%s",&str2);
printf("\nBefore concatenate : \n");
printf("String 1 : %s",str1);
printf("\nString 2 : %s",str2);
//calculating length of 1st string
for(i=0;str1[i]!=0;i++)
{
len=len+1;
}
//concatenate logic without string function
for(i=len,j=0;str2[j]!=0;i++,j++)
{
str1[i]=str2[j];
}
str1[i]='\0';//mentioning end of string
printf("\nAfter concatenate : \n");
printf("String 1 : %s",str1);
printf("\nString 2 : %s",str2);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[20],str2[20],ch;
int i,j,len=0;
clrscr();
printf("Enter 1st string : ");
scanf("%s",&str1);
printf("Enter 2nd string : ");
scanf("%s",&str2);
printf("\nBefore concatenate : \n");
printf("String 1 : %s",str1);
printf("\nString 2 : %s",str2);
//calculating length of 1st string
for(i=0;str1[i]!=0;i++)
{
len=len+1;
}
//concatenate logic without string function
for(i=len,j=0;str2[j]!=0;i++,j++)
{
str1[i]=str2[j];
}
str1[i]='\0';//mentioning end of string
printf("\nAfter concatenate : \n");
printf("String 1 : %s",str1);
printf("\nString 2 : %s",str2);
getch();
}

No comments:
Post a Comment