Advertisement
6_2008-2009 Debugging and Error Handling #203318

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

एआई सारांश: 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.

सोर्स कोड
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;
}
मूल टिप्पणियाँ (3)
Wayback Machine से पुनर्प्राप्त