Advertisement
4_2005-2006 Debugging and Error Handling #158282

String Replacement (str_replace)

This gives you the ability to use str_replace in C. str_replace is a very powerful function with many applications.

AI

Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kode Sumber
original-source
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//replaces all occurences with another occurence
char *str_replace(char * t1, char * t2, char * t6){
	char*t4;
	char*t5=malloc(0);
	while(strstr(t6,t1)){
		t4=strstr(t6,t1);
		strncpy(t5+strlen(t5),t6,t4-t6);
		strcat(t5,t2);
		t4+=strlen(t1);
		t6=t4;
	}
	return strcat(t5,t4);
}
int main(){
	printf("%s",str_replace("hello","goodbye","hello worldhello hello hello helloworld hello hello hello hello hellohello worldhello hello hello helloworld hello hello hello hello hellohello worldhello hello hello helloworld hello hello hello hello hello,and then it gets to the new line?\n"));
	return 0;
}
Komentar Asli (3)
Dipulihkan dari Wayback Machine