Concat two string with most overlapped substring has to
remove  "abcd"+ "cdef" = "abcdef

Answers were Sorted based on User's Feedback



Concat two string with most overlapped substring has to remove  "abcd"+ "cdef"..

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

Concat two string with most overlapped substring has to remove  "abcd"+ "cdef"..

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

Concat two string with most overlapped substring has to remove  "abcd"+ "cdef"..

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

Concat two string with most overlapped substring has to remove  "abcd"+ "cdef"..

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

Concat two string with most overlapped substring has to remove  "abcd"+ "cdef"..

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

Concat two string with most overlapped substring has to remove  "abcd"+ "cdef"..

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

Post New Answer

More C Interview Questions

what are bit fields in c?

0 Answers  


biggest of two no's with out using if condition statement

5 Answers  


What is a example of a variable?

0 Answers  


array contains zeros and ones as elements.we need to bring zeros one side and one other side in single parse. ex:a[]={0,0,1,0,1,1,0,0} o/p={0,0,0,0,0,1,1,1}

12 Answers   Google, Motorola,


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

0 Answers  






What are conditional operators in C?

0 Answers   Adobe,


What is the difference between far and near ?

0 Answers  


how to go with this?

1 Answers   Wipro,


what is the little endian and big endian?

1 Answers  


Explain what is the difference between declaring a variable and defining a variable?

1 Answers  


What is the memory allocated by the following definition ? int (*x)();

2 Answers   ADITI,


how many keywords do C compile?

7 Answers   Microsoft, Practical Viva Questions,


Categories