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
Explain the red-black trees?
pierrot's divisor program using c or c++ code
When would you use a pointer to a function?
Do you have any idea about the use of "auto" keyword?
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
Explain can you assign a different address to an array tag?
Are bit fields portable?
What is the general form of function in c?
Explain indirection?
What is type qualifiers?
Where are local variables stored in c?
Is void a keyword in c?
What is the ANSI C Standard?
Declare the structure which contains the following members and write in C list of all students who score more than 75 marks. Roll No, Name, Father Name, Age, City, Marks.
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?