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 does main () mean in c?
we called a function and passed something do it we have always passed the "values" of variables to the called function. such functions calles are called a) calls by reference b) calls by value c) calls by zero d) none of the above
write a program to display all prime numbers
code for replace tabs with equivalent number of blanks
Place the #include statement must be written in the program?
What is null pointer in c?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What does the file stdio.h contain?
What is bubble sort technique in c?
What is sizeof array in c?
What are high level languages like C and FORTRAN also known as?
Write a program to print "hello world" without using a semicolon?
Why void main is used in c?
Explain continue keyword in c
What are the ways to a null pointer can use in c programming language?