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
What are the 4 data types?
What is the difference between array_name and &array_name?
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?
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
What is sizeof array?
Is printf a keyword?
What are the c keywords?
How to establish connection with oracle database software from c language?
Can an array be an Ivalue?
What are the benefits of organizational structure?
What is the difference between text and binary modes?
Why dont c comments nest?
Explain what is the difference between far and near ?
What are c identifiers?
How can I manipulate individual bits?