49 lines
776 B
C++
49 lines
776 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 07/03/2025
|
|
|
|
es4A: Scrivere una funzione che modifichi la stringa
|
|
str eliminandone tutte le occorrenze del carattere ch.
|
|
Prototipo richiesto:
|
|
char *delchar(char * const str, const char ch);
|
|
Esempi:
|
|
"programma", 'a' -> "prgrmm"
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
char *delchar(char * const str, const char ch);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
char ch = 'a';
|
|
|
|
cin.getline(str, SIZE);
|
|
|
|
cin >> ch;
|
|
|
|
cout << delchar(str, ch);
|
|
|
|
return 0;
|
|
}
|
|
|
|
char *delchar(char * const str, const char ch) {
|
|
int j = 0;
|
|
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (str[i] != ch) {
|
|
str[j] = str[i];
|
|
j++;
|
|
}
|
|
}
|
|
|
|
str[j] = '\0';
|
|
|
|
return str;
|
|
} |