1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| char* occ(char CH1[],char CH2[]){
int len_CH1, len_CH2;
len_CH1 = nbr_carac(CH1);
len_CH2 = nbr_carac(CH2);
if ((len_CH1 > 0) && (len_CH2 > 0) && (len_CH2 >= len_CH1)) {
int step_CH1, step_CH2;
unsigned char is_not_found;
is_not_found = 1; /* true */
for (step_CH2=0; ((step_CH2 < len_CH2) && is_not_found); step_CH2++){
for (step_CH1=0; ((step_CH1 < len_CH1) && (CH2[step_CH2 + step_CH1] == CH1[step_CH1])); step_CH1++) {}
if (step_CH1 == len_CH1) { is_not_found = 0; }
}
if (!is_not_found) {
--step_CH2; /* the loop for increments one more time */
printf("occ - debug : [%d character%s ... pos : %d -> %d (len : %d)]\n", step_CH2, ((step_CH2 > 1)? "s": ""), (step_CH2 + len_CH1), len_CH2, (len_CH2 - (step_CH2 + len_CH1) + 1));
/* XXX careful : test if memcpy works with inplace copies */
memcpy((CH2 + step_CH2), (CH2 + step_CH2 + len_CH1), (len_CH2 - (step_CH2 + len_CH1) + 1));
/* CH2[step_CH2 + len_CH1] = '\0'; */ /* maybe useless */
}
}
return CH2;
} |
Partager