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 4 data types?

604


What is the difference between array_name and &array_name?

781


How to write a program for machine which is connected with server for that server automatically wants to catch the time for user of that machine?

1594


main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none

728


What is sizeof array?

615






Is printf a keyword?

762


What are the c keywords?

752


How to establish connection with oracle database software from c language?

1679


Can an array be an Ivalue?

668


What are the benefits of organizational structure?

577


What is the difference between text and binary modes?

650


Why dont c comments nest?

625


Explain what is the difference between far and near ?

655


What are c identifiers?

631


How can I manipulate individual bits?

611