Waitrud Weber’s blog

things and reminders for memories

Analyzer: windows-make: m_replace is qualified and still remained memorization error at work.

1
.\array_counter.cpp  Tue Mar 16 04:47:25 2021
...
124 :char* m_replace ( char* char_string,
125 : char* from_string, char* to_string ) {
126 :	char c1, c2, c11;
127 :	int count = array_count( char_string );
128 :	int a_f = array_count( from_string );
129 :	int a_t = array_count( to_string );
130 :	int a_c = 0;
131 :	char* char_string_2 = 
132 :	  (char *) malloc ( sizeof (char)*( count + a_t - 1 ) );
133 :
134 :	c2 = 0;
135 :	int cnt_replace = 0;
136 :	for ( int i = 0; i<count; i++ ) {
137 :		c1 = *( char_string + i ) ;
138 :		a_c = 0;
   
 
139 :		for ( int j=0; j<a_f && j <count; j++ ) {
   
 
140 :			c11 = *( char_string + i + j ) ;
141 :			c2 = *( from_string + j ) ;
142 :			if ( c11 != c2 ) break;
143 :			a_c++;
144 :		}
145 :
146 :		err_msg_001("i|%d| c1|%d|=|%c| a_c=%d a_f=%d c2|%d||%c|\r\n", i, c1, c1, a_c, a_f, c2, c2 );
147 :		if ( a_c == a_f && cnt_replace >= 0) {
148 :			// match
149 :			int to = i + a_t;
150 :			for( int k=0; k<a_t; k++ ) {
151 :				err_msg_001("replace string k=|%d|%c|\r\n", k, *( to_string + k ));
152 :				*( char_string_2 + i + k + cnt_replace*(a_t- a_f ) ) = 
153 :				  *( to_string + k );
154 :			}
155 :			i = to;
156 :			cnt_replace++;
157 :		} else {
158 :			*( char_string_2 + i + cnt_replace*(a_t- a_f ) ) = c1;
159 :		}
160 :	}
161 :	*( char_string_2 + count + cnt_replace*( a_t - a_f ) ) = '\0';
162 :	put_memories ( char_string_2 );
163 :
164 :	return char_string_2;
165 :}
   
 
replace.cpp  Tue Mar 16 05:20:24 2021
...
163 :int replace_csv ( char* form_file ) {
164 :	char str_num[10];
165 :	char* string;
166 :	printf("replace_csv starts.\r\n");
167 :	sleep(1);
168 :	// if we read a file all, memorization is changed wrong.
169 :	string = read_all(form_file);
170 :
171 :	for( int i =0; i<3; i++ ) {
172 :		for( int j =0; j<3; j++ ) {
173 :			sprintf( str_num, "$%d%d", i, j );
174 ://			printf("i %d j %d {%p} |%s|: ", i, j, csv[i][j], (char*)csv[i][j]);
175 :			if ( csv[i][j] != nullptr ) {
176 :				int a_001 = array_count ( string );
177 :				string = m_replace ( string, str_num, csv[i][j] );
178 :				int a_002 = array_count ( string );
179 :				// debug 20210316
180 :				if ( abs ( a_001 - a_002 ) > 30 ) {
181 :					printf("replaced string is changed a lot, so, it's going to exit.\r\n|%s|\r\n", string);
182 :					exit(-1);
183 :				}
184 :			}
185 :
186 :			printf("replace: %d %d |%s|%s|:\r\n|%s|\r\n", i, j, str_num, csv[i][j], string);
187 :			sleep(1);
188 :		}
189 :	}
190 :
191 :	write_block( ".\\001-html-20210316-001\.txt", string );
192 :	printf("replace_csv ends.\r\n");
193 :	return -1;
194 :}
   
 

 ---
i|607| c1|60|=|<| a_c=0 a_f=3 c2|36||$|
i|608| c1|47|=|/| a_c=0 a_f=3 c2|36||$|
i|609| c1|116|=|t| a_c=0 a_f=3 c2|36||$|
i|610| c1|97|=|a| a_c=0 a_f=3 c2|36||$|
i|611| c1|98|=|b| a_c=0 a_f=3 c2|36||$|
i|612| c1|108|=|l| a_c=0 a_f=3 c2|36||$|
i|613| c1|101|=|e| a_c=0 a_f=3 c2|36||$|
i|614| c1|62|=|>| a_c=0 a_f=3 c2|36||$|
| a_c=0 a_f=3 c2|36||$|
i|616| c1|10|=|
| a_c=0 a_f=3 c2|36||$|
replaced string is changed a lot, so, it's going to exit.
|<table>
<tr><td>0 </td><td> axes}6|
---

*
index i went to 616 like printed.
---

   
6

https://github.com/WaitrudWeber/source_zip/blob/master/replace_20210316-001-01.zip

   
7

https://github.com/WaitrudWeber/source_zip/blob/master/replace_20210316-001-02.zip

   
8

https://github.com/WaitrudWeber/source_zip/blob/master/replace_20210316-001-03.zip