Come detto da Andretti sopra, 2 loops.
C++:#include <iostream> using namespace std; int main() { char word[] = "Hell.o W@orld"; char badSymbols[] = ".@[]{}()"; //controlla ogni caratter for (char* currentChar = word; *currentChar != '\0' ; currentChar++) { //controlla contro ogni simbolo for (char* symbol = badSymbols; *symbol != '\0'; symbol++) { //se un carattere indesiderato viene trovato if (*currentChar == *symbol) { //rimuovilo char* next = currentChar; while (*next != '\0') { *next = *(next + 1); next++; } } } } for (char* ch = word; *ch != '\0'; ch++){ cout << *ch; } return 0; }
nel codice che rimuove, puoi anche risparmiare una linea scrivendo questo (anzichè next++ in una linea separata)
C++:while (*next != '\0'){ *next++ = *(next + 1); }
ho problemi con il codice nel main richiamo la funzione rimuovistringa(stringa);
dove stringa è un array di caratteri;
nella funzione gli passo un puntatore a caratteri;
ma non la stampa la stringa