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


Please Help Members By Posting Answers For Below Questions

What are the __date__ and __time__ preprocessor commands?

777


What is null in c?

754


What is variables in c?

803


What is NULL pointer?

859


What does nil mean in c?

905


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1697


What is a constant?

814


how to count no of words,characters,lines in a paragraph.

4157


What are the key features in c programming language?

822


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

2146


What is the maximum length of an identifier?

894


Why is c still so popular?

792


List the difference between a While & Do While loops?

848


Why we not create function inside function.

1966


How to explain the final year project as a fresher please answer with sample project

718