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.
Post History
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. ...
#8: Post edited
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.
#7: Post edited
Haskell Question
- How to efficiently remove every occurrence of one string inside another
> Write a program that takes in three integers which represent the three sides of a triangle and returns appropriate Boolean values using 'strtok'. The program should ask to enter the 3 sides and deduce (True/False) whether the triangle is Isosceles, Equilateral...
- 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.
#6: Post edited
How to efficiently remove every occurrence of one string inside another
- Haskell Question
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 to so in C in a time efficient way, i.e. probably with the lowest number of comparisons and include/copy actions.
- > Write a program that takes in three integers which represent the three sides of a triangle and returns appropriate Boolean values using 'strtok'. The program should ask to enter the 3 sides and deduce (True/False) whether the triangle is Isosceles, Equilateral...
#4: Post edited
How do you remove every occurrence of the second string inside the first one?
- How to efficiently remove every occurrence of one string inside another
I came across a sample practice question on the internet. How do you remove every occurence of the second string inside the first one?> Write a program that reads two strings of less than 30 characters and removesevery occurrence of the second string inside the first one. After each removal, theremaining part of the first string should be shifted to the left, a number of placesequal to the characters of the second string. The program should display the firststring, before it ends. Here's my progress so far:```#include <stdio.h>#include <stdlib.h>#include <string.h>char *new_string(char *, char *);int main(void){char *str1, *str2, *ptr3;str1 = malloc(30 * sizeof(char));printf("Enter first text: ");fgets(str1, 30, stdin);str2 = malloc(30 * sizeof(char));printf("Enter second text: ");fgets(str2, 30, stdin);ptr3 = new_string(str1, str2);if (ptr3 == NULL)printf("String 1 has been removed totally");else {printf("");}return 0;}char *new_string(char *str1, char *str2){//need some help here}```
- 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 to so in C in a time efficient way, i.e. probably with the lowest number of comparisons and include/copy actions.
#2: Post edited
- I came across a sample practice question on the internet. How do you remove every occurence of the second string inside the first one?
- > Write a program that reads two strings of less than 30 characters and removes
- every occurrence of the second string inside the first one. After each removal, the
- remaining part of the first string should be shifted to the left, a number of places
- equal to the characters of the second string. The program should display the first
- string, before it ends. Here's my progress so far:
- ```#include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *new_string(char *, char *);
- int main(void)
- {
- char *str1, *str2, *ptr3;
- str1 = malloc(30 * sizeof(char));
- printf("Enter first text: ");
fgets(str1, 30, stdin);//must use fgets- str2 = malloc(30 * sizeof(char));
- printf("Enter second text: ");
fgets(str2, 30, stdin);//must use fgets- ptr3 = new_string(str1, str2);
- if (ptr3 == NULL)
- printf("String 1 has been removed totally");
- else {
- printf("");
- }
- return 0;
- }
- char *new_string(char *str1, char *str2){
- //need some help here
- }
- ```
- I came across a sample practice question on the internet. How do you remove every occurence of the second string inside the first one?
- > Write a program that reads two strings of less than 30 characters and removes
- every occurrence of the second string inside the first one. After each removal, the
- remaining part of the first string should be shifted to the left, a number of places
- equal to the characters of the second string. The program should display the first
- string, before it ends. Here's my progress so far:
- ```#include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *new_string(char *, char *);
- int main(void)
- {
- char *str1, *str2, *ptr3;
- str1 = malloc(30 * sizeof(char));
- printf("Enter first text: ");
- fgets(str1, 30, stdin);
- str2 = malloc(30 * sizeof(char));
- printf("Enter second text: ");
- fgets(str2, 30, stdin);
- ptr3 = new_string(str1, str2);
- if (ptr3 == NULL)
- printf("String 1 has been removed totally");
- else {
- printf("");
- }
- return 0;
- }
- char *new_string(char *str1, char *str2){
- //need some help here
- }
- ```
#1: Initial revision
How do you remove every occurrence of the second string inside the first one?
I came across a sample practice question on the internet. How do you remove every occurence of the second string inside the first one? > Write a program that reads two strings of less than 30 characters and removes every occurrence of the second string inside the first one. After each removal, the remaining part of the first string should be shifted to the left, a number of places equal to the characters of the second string. The program should display the first string, before it ends. Here's my progress so far: ```#include <stdio.h> #include <stdlib.h> #include <string.h> char *new_string(char *, char *); int main(void) { char *str1, *str2, *ptr3; str1 = malloc(30 * sizeof(char)); printf("Enter first text: "); fgets(str1, 30, stdin);//must use fgets str2 = malloc(30 * sizeof(char)); printf("Enter second text: "); fgets(str2, 30, stdin);//must use fgets ptr3 = new_string(str1, str2); if (ptr3 == NULL) printf("String 1 has been removed totally"); else { printf(""); } return 0; } char *new_string(char *str1, char *str2){ //need some help here } ```