Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How to efficiently remove every occurrence of one string inside another
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.
1 answer
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"}```
5 comment threads