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
If I have a char * variable pointing to the name of a function ..
What is the difference between mpi and openmp?
Differentiate between a structure and a union.
How many levels of pointers can you have?
What are the 5 elements of structure?
What is a structure and why it is used?
Is c dynamically typed?
How does sizeof know array size?
What is assert and when would I use it?
What is this infamous null pointer, anyway?
What are loops in c?
What is the difference between memcpy and memmove?
How to write a code for implementing my own printf() and
scanf().... Please hep me in this... I need a guidance...
Can you give an coding for c... Please also explain about
the header files used other than #include
Write a program for finding factorial of a number.
What is a stream?