ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
   
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
Concat two string with most overlapped substring has to 
remove  "abcd"+ "cdef" = "abcdef
 Question Submitted By :: San
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef
Answer
# 1
#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 5 No
Tarak
 
  Re: Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef
Answer
# 2
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
Durga Prasad
 
 
 
  Re: Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef
Answer
# 3
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
Sham
 
  Re: Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef
Answer
# 4
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
Sham
 
  Re: Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef
Answer
# 5
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
Ashwin Kumar
 
  Re: Concat two string with most overlapped substring has to remove  "abcd"+ "cdef" = "abcdef
Answer
# 6
@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
Om
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
dibakar & vekatesh..uttejana here..abt ur reply for in place reversal of linked list..wats p stands for there?  1
1 232 34543 4567654 can anyone tell me how to slove this c question  6
Program to write some contents into a file using file operations with proper error messages.  2
Read two numbers from keyboard and find maximum of them?  1
for(;;) printf("C language") What is out put of above??  2
why we use "include" word before calling the header file. is there any special name for that include?????? Tcs1
how to implement stack work as a queue?  2
get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement  3
enum day = { jan = 1 ,feb=4, april, may} what is the value of may? a)4 b)5 c)6 d)11 e)none of the above HCL7
main() { intx=2,y=6,z=6; x=y=z; printf(%d",x) } HCL5
find second largest element in array w/o using sorting techniques? use onle one for loop. Zycus-Infotech14
we have to use realloc only after malloc or calloc ? or we can use initially with out depending on whether we are using malloc or calloc in our program ?  2
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2012  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com