39 lines
753 B
C
39 lines
753 B
C
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
int charErase (char str[], int pos[]) {
|
|
int l = strlen(str);
|
|
int * atp = pos;
|
|
int steps = 0;
|
|
|
|
// segno con -1 i caratteri da eliminare
|
|
while (*atp != -1) {
|
|
if (*atp < l)
|
|
str[*atp] = -1; // nessun carattere ascii ha codice -1, è una flag valida
|
|
|
|
atp++;
|
|
}
|
|
|
|
for (int i = 0; i < l; i++) {
|
|
while (str[i + steps] == -1) {
|
|
steps++;
|
|
|
|
if (i + steps >= l)
|
|
break;
|
|
}
|
|
|
|
str[i] = str[i + steps];
|
|
}
|
|
|
|
str[l-steps] = 0;
|
|
return steps;
|
|
}
|
|
|
|
int main(){
|
|
char sus[] = "ThisIsAString";
|
|
int arr[] = {7, 4, 2, 0, 11, -1};
|
|
printf("%d",charErase(sus, arr));
|
|
puts(sus);
|
|
return 0;
|
|
}
|