code for concatination of 2 strings with out using library
functions?
Answer Posted / 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 |
Post New Answer View All Answers
What are the characteristics of arrays in c?
write a program to rearrange the array such way that all even elements should come first and next come odd
What is a pointer variable in c language?
How do you determine a file’s attributes?
What is the difference between array_name and &array_name?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
what are the program that using a two dimensional array that list the odd numbers and even numbers separately in a given 10 inputs values
Describe how arrays can be passed to a user defined function
What is hash table in c?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
What are structure members?
Write a program which returns the first non repetitive character in the string?
How to create struct variables?
How do we print only part of a string in c?
What is 02d in c?