Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Q&A

How to efficiently remove every occurrence of one string inside another

+1
−8

I have two strings and want to remove every occurrence of the second string inside the first one starting from the beginning of the first string and as if each occurrence was removed immediately. I would like to do so in C in a time-efficient way, i.e. probably with the lowest number of comparisons and include/copy actions.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

5 comment threads

Do My Homework? (1 comment)
Please indicate the actual problem you are having (1 comment)
Maybe add examples? The word "immediately" is not clear; maybe best to clarify it with examples. Also... (2 comments)
Too broad (4 comments)
Concentrate on the core problem (3 comments)

1 answer

+1
−2

I've accidentally disabled my account hence I'm answering the questions that I've answered before again. Adding on to this, I feel like adding a comment, please do bear in mind that this code isn't necessarily working.

Solution:

myProgram = do {
   putStrLn "Enter three sides: ";
   str<-getLine;
   putStr "RightAngle: ";
   print (snd(head (classify (head (strtok str)) (strtok str!!1) (strtok str!!2))));
   putStr "Isosceles: ";
   print (snd (classify (head (strtok str)) (strtok str!!1) (strtok str!!2)!!1));
   putStr "Equilateral: ";
   print (snd(classify (head (strtok str)) (strtok str!!1) (strtok str!!2)!!2));
   putStr "Scalene: ";
   print (snd(classify (head (strtok str)) (strtok str!!1) (strtok str!!2)!!3));
   putStr "End"}```



Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Question was rolled back, so this answer is obsolete (1 comment)

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate