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
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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.

Comments on How to efficiently remove every occurrence of one string inside another

Post

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.

History
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)
Too broad
Lundin‭ wrote over 2 years ago · edited over 2 years ago

I started to write a pseudo-code answer but the question is simply too broad. You need to use strstr, you need to use strcpy, you need to write a loop. Explaining how to do these things in detail is the task of the string handling chapter in your C book. I voted to close it as "too generic", please try to ask specific questions rather than questions of the nature "how do I write this whole program".

Trilarion‭ wrote over 2 years ago

Maybe we could assume that the asker has knowledge of C but doesn't know of any algorithm to accomplish the task. An answer could then first explain a suitable algorithm (relying only on tools available in C) and then simply present an implementation in C without much explanation. That's at least the way I thought about it, when editing the question.

Lundin‭ wrote over 2 years ago

Trilarion‭ I don't think such an answer will be of particular high quality. This is best answered by studying the string handling chapter in a C book, then make an attempt to solve the problem and ask specific questions about the code when stuck.

Trilarion‭ wrote over 2 years ago

@Lundin You mean there is no complete solution to the whole problem possible within reasonable space in an answer or it would not be instructive to read about the whole solution in one go? I mostly take home that the problem might still be too broad and needs to be divided into smaller pieces.