feat: Initial commit
This commit is contained in:
38
TemiEsame/charErase.c
Normal file
38
TemiEsame/charErase.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user