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 is c language.

3 Answers  


What is a pointer and how it is initialized?

0 Answers  


A array contains dissimilar element how can we count, and A array contains dissimilar element how can we store in another array with out repetition.

4 Answers  


What functions are used for dynamic memory allocation in c language?

0 Answers  


explain what is fifo?

0 Answers  






What is the use of putchar function?

0 Answers  


How to convert decimal to binary in C using recursion??

4 Answers   HP, IBM,


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

1 Answers   IBM,


Why is c so powerful?

0 Answers  


void main() { int a[]={1,2,3,4,5},i; for(i=0;i<5;i++) printf("%d",a++); getch(); }

3 Answers  


Can you pass an entire structure to functions?

0 Answers  


Differentiate between new and malloc(), delete and free() ?

0 Answers   iNautix,


Categories