Am trying to build a function that will take string, sub_string that will be replaced, and new string that will replace that sub_string. Now before you all go with strstr, i dont want to use <string>. Anyway I got my code working to find a index of a char array from rewritting should start. consider this code :
string replace_string(char *original, char *new_n, int index,int size_of_org,int size_of_sub, int size_of_new) {
// original - string provided by user
// new_n - string to replace a sub_string
// index - index of a 1st character of a substring
// size of user provided string, size of sub_string, size of string that will replace sub_string
int d = 0;
int difference_in_size;
int Size;
difference_in_size = size_of_new - size_of_sub; // used if sub_string and new_n are not same lenght
Size = size_of_org + difference_in_size; // calculating size for our string that will be ouput in the end
char new_char_niz[Size];
cout << "size : " << Size <<endl;
for(int x = 0; x < size_of_org +1 ; x++){
new_char_niz[x] = original[x]; // am copyng a user provided string to our newly created char array
}
//for(int y = index;y < size_of_new+1; y++){ // Part I cant figure out.
//new_char_niz[y] == new_n[d++]; // starting at target index, copy every element to our new string
//}
string new_string(new_char_niz); // convert to string
return new_string;
}
Any suggestion for solution of this issue is a big Thank You.