0

I have to manipulate strings so that, we need to check if a string needs to be combined with another string. Need to use a library function for this.

Suppose, we have

S1. This is an apple
s2. apple is sweet
so, the combined line should be: This is an apple is sweet

s1. This is an apple
s2. e that I bought
Combined: This is an apple that I bought

I used nested for loops for this and it makes it too complicated. Is there a string library function that I can use?

I will have bunch of lines of sentences, and I need to combine them to form one sentence.
I need to combine lines that match the most, not just 2 lines that match.

Edited by allensmith: n/a

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by c coder
0

Take a look at strcat.
But strcat on it's own won't solve the whole thing, you'll have to do some other things as well, things which I'd like you to try figure them out on your own.
When you run into problems you still can fall back to this thread.

0

I have to manipulate strings so that, we need to check if a string needs to be combined with another string. Need to use a library function for this.

Suppose, we have

S1. This is an apple
s2. apple is sweet
so, the combined line should be: This is an apple is sweet

s1. This is an apple
s2. e that I bought
Combined: This is an apple that I bought

I used nested for loops for this and it makes it too complicated. Is there a string library function that I can use?

I will have bunch of lines of sentences, and I need to combine them to form one sentence.
I need to combine lines that match the most, not just 2 lines that match.

U can use the functions strstr() and strcat() to do the above. Read their manual.

Edited by dkalita: n/a

-2
**********************answer
#include<stdio.h>
void main()
{int i,j;
 char str1[30];
char str2[15];

puts("enter string1");
gets(str1);
puts("enter string 2");
gets(str2);



for(j=0,i=0;str1[i]!='\0';i++)
{
    if(str2[j]==str1[i])
    {
    printf("%c",str2[j]);
    j++;

    }


}

    while(str2[j]!='\0')
    { str1[i]=str2[j];
     j++;
        i++;
    }
str1[i]='\0';
printf("%s",str1);
}
*******************

Edited by Dani: Formatting fixed

Votes + Comments
Seconded.
using gets(), void main(), no CODE tags, and answering the question without letting allensmith try it first
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.