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
How many identifiers are there in c?
What are the keywords in c?
What is the use of pragma in embedded c?
What does struct node * mean?
What is the meaning of 2d in c?
Write a program that accept anumber in words
Is it possible to initialize a variable at the time it was declared?
What are the different types of constants?
What is a void pointer in c?
Which is better oop or procedural?
When is a null pointer used?
How can I do peek and poke in c?
hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...
Difference between Shallow copy and Deep copy?
What are enumerated types?