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
Avatar of phoffric
phoffric

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

ASKER

I have updated my question. Hope this will help.

Thanks
Avatar of phoffric
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
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
C
C

C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, so it has found lasting use in applications that had formerly been coded in assembly language, including operating systems as well as various application software for computers ranging from supercomputers to embedded systems. It is distinct from C++ (which has its roots in C) and C#, and many later languages have borrowed directly or indirectly from C.

23K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo