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 what is a static function?
Why should I prototype a function?
WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..
What is meant by int main ()?
write a program fibonacci series and palindrome program in c
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above
I need testPalindrome and removeSpace
#include
Whats s or c mean?
What is wrong with this declaration?
What is #line in c?
Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.
Explain how can I convert a number to a string?
How is a macro different from a function?
c program to compute AREA under integral
What is the argument of a function in c?