Concat two string with most overlapped substring has to
removeĀ "abcd"+ "cdef" = "abcdef
Answer Posted / ashwin kumar
the code given by tarak is correct
ie
#include<stdio.h>
main()
{
char *a="abcd";
char *b="cdef";
char c[10];
int i=0;
while(*a != *b)
{
c[i] = *a++;
i++;
}
while(*b != '\0')
{
c[i]= *b++;
i++;
}
printf("%s\n",c);
}
but the answer is abcdef and some garbage values yar
abcdef{}>>>M<C<P{{
to get perfect answer just add '\o' at end of the code and
before printf dear
#include<stdio.h>
main()
{
char *a="abcd";
char *b="cdef";
char c[10];
int i=0;
while(*a != *b)
{
c[i] = *a++;
i++;
}
while(*b != '\0')
{
c[i]= *b++;
i++;
}
c[i]='\0'; //// new added line here
printf("%s\n",c);
}
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is nested structure in c?
Hi how many types of software editions are there and their difference (like home editions, enterprise, standard etc) can u please help me
How can I run c program?
Why is c called a mid-level programming language?
Explain about the functions strcat() and strcmp()?
write a program that types this pattern: 12345678987654321 12345678 87654321 1234567 7654321 123456 654321 12345 54321 1234 4321 123 321 12 21 1 1
Explain what is the difference between #include and #include 'file' ?
What is an lvalue in c?
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
What is wrong with this declaration?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
Which header file is essential for using strcmp function?
What is the default value of local and global variables in c?
Define C in your own Language.