Avatar of Dinesh Bali
Dinesh Bali asked on

Algorithm

I have exam in C, Data Structure.
Write and explain the algorithms to insert and delete a string from a given text?

I am finding response to my above question. I am not finding best suited answer for my above question.

Thanks
C

Avatar of undefined
Last Comment
phoffric

8/22/2022 - Mon
phoffric

Please post what you have and show us where you are having trouble.
ASKER
Dinesh Bali

I have updated my question. Hope this will help.

Thanks
phoffric

Well, I was looking for you to post what you have and show us where you are having trouble. I will not be available for a few days after today.
Are you looking for C-code (since you chose the C-zone)? I did a quick search and found this code which is close to what you want for the delete part.
// ----codescracker.com----

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str[100], word[20];
    int i, j, ls, lw, temp, chk=0;
    printf("Enter the String: ");
    gets(str);
    printf("Enter a Word: ");
    gets(word);
    ls = strlen(str);
    lw = strlen(word);
    for(i=0; i<ls; i++)
    {
        temp = i;
        for(j=0; j<lw; j++)
        {
            if(str[i]==word[j])
                i++;
        }
        chk = i-temp;
        if(chk==lw)
        {
            i = temp;
            for(j=i; j<(ls-lw); j++)
                str[j] = str[j+lw];
            ls = ls-lw;
            str[j]='\0';
        }
    }
    printf("\nNew String = %s", str);
    getch();
    return 0;
}

Open in new window

Delete Word from String
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
phoffric

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question