in turboc++
-----------------------------------------------------------------------------------------
//WAP to concatenate two strings without using(strcat()) function.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char st[100],st1[100];//two string declaration
int i,j;
printf("enter first string\n");
//fgets(name, sizeof (name), stdin);//to input string with space
scanf("%s",st); //it also CAN BE USED. IT accepts string with space until it meets new line
printf("enter second string\n");
scanf("%s",st1);
for(i=0;st[i]!='\0';i++);//to get last value of i of first string
for(j=0;st1[j]!='\0';j++)//loop execution till null character
{
st[i]=st1[j];//copying characters
i++;
}
st[i]='\0';//adds an extra null character at the end.
printf("concatenated string =%s\n",st);//prints the merged string
getch();
return 0;
}
---------------------------------------------------------------------------------------------------------
in codeblocks:
-----------------------------------------------------------------------------------------
//WAP to concatenate two strings without using(strcat()) function.
#include <stdio.h>
#include<string.h>
int main()
{
char st[100],st1[100];//two string declaration
int i,j;
printf("enter first string\n");
//fgets(name, sizeof (name), stdin);//to input string with space
scanf("%s",st); //it also CAN BE USED. IT accepts string with space until it meets new line
printf("enter second string\n");
scanf("%s",st1);
for(i=0;st[i]!='\0';i++);//to get last value of i of first string
for(j=0;st1[j]!='\0';j++)//loop execution till null character
{
st[i]=st1[j];//copying characters
i++;
}
st[i]='\0';//adds an extra null character at the end.
printf("concatenated string =%s\n",st);//prints the merged string
return 0;
}
-----------------------------------------------------------------------------------------
//WAP to concatenate two strings without using(strcat()) function.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char st[100],st1[100];//two string declaration
int i,j;
printf("enter first string\n");
//fgets(name, sizeof (name), stdin);//to input string with space
scanf("%s",st); //it also CAN BE USED. IT accepts string with space until it meets new line
printf("enter second string\n");
scanf("%s",st1);
for(i=0;st[i]!='\0';i++);//to get last value of i of first string
for(j=0;st1[j]!='\0';j++)//loop execution till null character
{
st[i]=st1[j];//copying characters
i++;
}
st[i]='\0';//adds an extra null character at the end.
printf("concatenated string =%s\n",st);//prints the merged string
getch();
return 0;
}
---------------------------------------------------------------------------------------------------------
in codeblocks:
-----------------------------------------------------------------------------------------
//WAP to concatenate two strings without using(strcat()) function.
#include <stdio.h>
#include<string.h>
int main()
{
char st[100],st1[100];//two string declaration
int i,j;
printf("enter first string\n");
//fgets(name, sizeof (name), stdin);//to input string with space
scanf("%s",st); //it also CAN BE USED. IT accepts string with space until it meets new line
printf("enter second string\n");
scanf("%s",st1);
for(i=0;st[i]!='\0';i++);//to get last value of i of first string
for(j=0;st1[j]!='\0';j++)//loop execution till null character
{
st[i]=st1[j];//copying characters
i++;
}
st[i]='\0';//adds an extra null character at the end.
printf("concatenated string =%s\n",st);//prints the merged string
return 0;
}
No comments:
Post a Comment