code for concatination of 2 strings with out using library
functions?

Answers were Sorted based on User's Feedback



code for concatination of 2 strings with out using library functions?..

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

code for concatination of 2 strings with out using library functions?..

Answer / vignesh1988i

#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

code for concatination of 2 strings with out using library functions?..

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

Post New Answer

More C Interview Questions

Can we include one C program into another C program if yes how?

7 Answers   Infosys,


Is fortran faster than c?

0 Answers  


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?

0 Answers  


what is a NULL Pointer? Whether it is same as an uninitialized pointer?

0 Answers   TISL,


What is meant by type specifiers?

0 Answers  


Write a C program in Fibonacci series.

0 Answers   iNautix,


What are the types of bitwise operator?

0 Answers  


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....

2 Answers  


What should malloc() do? Return a null pointer or a pointer to 0 bytes?

0 Answers  


What's the right way to use errno?

0 Answers  


How can I do serial ("comm") port I/O?

0 Answers   Celstream,


Categories