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 categories used for in c?
Which are low level languages?
What is bash c?
while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above
How do I use strcmp?
What is the size of empty structure in c?
Is a house a shell structure?
What tq means in chat?
What is the use of structure padding in c?
What is the use of a ‘ ’ character?
What is include directive in c?
Write a code to generate a series where the next element is the sum of last k terms.
How to compare array with pointer in c?
Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.
Write a program to reverse a linked list in c.