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 are the advantages and disadvantages of c language?
Why c is a mother language?
What is the use of linkage in c language?
What is the difference between formatted&unformatted i/o functions?
Can you write the algorithm for Queue?
What is difference between far and near pointers?
What is meant by inheritance?
What does a pointer variable always consist of?
What is meant by recursion?
What is a null pointer in c?
Write a c program to demonstrate character and string constants?
What is %lu in c?
Differentiate between functions getch() and getche().
Explain what is output redirection?
What is the difference between near, far and huge pointers?