code for concatination of 2 strings with out using library
functions?
Answers were Sorted based on User's Feedback
Answer / kiruthikau
[code]
#include<stdio.h>
#include<string.h>
main()
{
char one[]="hai";
char two[]=" hello";
int len1=strlen(one);
int len2=strlen(two);
char res[len1+len2];
int i,j;
for(i=0;i<len1;i++)
res[i]=one[i];
for(j=0;j<len2,i<len1+len2;i++,j++)
res[i]=two[j];
res[i]='\0';
printf("res:%s\n",res);
}
[/code]
If you don't want to use strlen() function also ,try the
following code.
[code]
#include<stdio.h>
#include<string.h>
main()
{
char one[]="hai";
char two[]=" hello";
int len1=0;
int len2=0;
int i=0;
int j;
while(one[i++]!='\0')
len1++;
i=0;
while(two[i++]!='\0')
len2++;
char res[len1+len2];
for(i=0;i<len1;i++)
res[i]=one[i];
for(j=0;j<len2,i<len1+len2;i++,j++)
res[i]=two[j];
res[i]='\0';
printf("res:%s\n",res);
}
[/code]
Is This Answer Correct ? | 5 Yes | 1 No |
#include<stdio.h>
#include<conio.h>
void strrcat(char *,char *);
void main()
{
char a[50],b[50];
int i;
clrscr();
printf("enter the string 1 :");
gets(a);
printf("enter the string 2 :");
gets(b);
strrcat(a,b);
gets(a);
getch();
}
void strrcat(char *a , char *b)
{
for(int i=0;*a!='\0';i++,a++);
for(int j=0;*b!='\0';j++,i++,b++,a++)
*a=*b;
*a='\0';
}
thank u :)
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / chavidi
void main()
{
char a[20],b[20];
int i,j,k;
gets(a);
gets(b);
i=strlen(a);
k=i+strlen(b);
j=0;
while(i<=k)
{
a[i]=b[j];
i++;
j++;
}
printf("Resultant String is %d :",a);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Can we include one C program into another C program if yes how?
Is fortran faster than c?
write a C code to reverse a string using a recursive function, without swapping or using an extra memory.
9 Answers Motorola, TCS, Wipro,
What does it mean when the linker says that _end is undefined?
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
What is meant by type specifiers?
Write a C program in Fibonacci series.
What are the types of bitwise operator?
which is the best site or book for learning C...and i need the content for C..how to get the good programming skills....? can plz suggest me....
What should malloc() do? Return a null pointer or a pointer to 0 bytes?
What's the right way to use errno?
How can I do serial ("comm") port I/O?