Concat two string with most overlapped substring has to
remove "abcd"+ "cdef" = "abcdef
Answers were Sorted based on User's Feedback
Answer / durga prasad
above code some thing wrong.
if "abcd","cefg" then output will be "abcdcefg"
but above code will give "abcefg"
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / sham
Check the each char in the second string with first string
if it is not there then concatenate into the first string else
do not do.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sham
char *strappend1(char *src,char *des)
{
char *tmp=src;
int f=0;
while(*des)
{
while(*src!='\0')
{
if(*src==*des)
{
f=0;
break;
}
else
f=1;
src++;
}
if(f==1)
{
*src++=*des;
*src='\0';
}
des++;
}
return tmp;
}
int main(int argc,char **argv)
{
char *src=argv[1],*des=argv[2];
char *str;
str=strappend1(src,des);
printf("%s",str);
}
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / 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 |
Answer / om
@Ashwin Kumar
According to your program....
char *a="abcdcdcd";
char *b="cdef";
output is "abcdef"..//which is wrong.....it should be abcdcdef
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / tarak
#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);
}
Is This Answer Correct ? | 4 Yes | 6 No |
How do I determine whether a character is numeric, alphabetic, and so on?
In the following control structure which is faster? 1.Switch 2.If-else and which consumes more memory?
Explain what does a function declared as pascal do differently?
What are register variables? What are the advantage of using register variables?
How does selection sort work in c?
void main() {int i=2; printf("%d%d%d",i,++i,i++); getch(); }
How Many Header Files in c?
Write a program to remove the C comments(/* */) and C++ comments(//) from a file. The file should be declared in command line.
write a program in c to find out the sum of digits of a number.but here is a condition that compiler sums the value from left to right....not right to left..
What is a char in c?
Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will this compile?
If we give two names then this displays the connection between the two people. It is nothing but flames game