47 lines
732 B
C++
47 lines
732 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 07/03/2025
|
|
|
|
es4I: Scrivere una funzione che, ricevuta in
|
|
input una stringa, elimini tutti gli spazi a dx.
|
|
Prototipo richiesto:
|
|
char *strrtrim(char * const str);
|
|
Esempio: " ciao mondo " -> " ciao mondo"
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cctype>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
char *strrtrim(char * const str);
|
|
|
|
int main(void) {
|
|
char str[] = "Hello World ";
|
|
|
|
cout << str << "|" << endl;
|
|
|
|
cout << strrtrim(str) << "|";
|
|
|
|
return 0;
|
|
}
|
|
|
|
char *strrtrim(char * const str) {
|
|
int i = 0;
|
|
|
|
while (str[i] != '\0') {
|
|
i++;
|
|
}
|
|
|
|
while (i > 0 && str[i - 1] == ' ') {
|
|
i--;
|
|
}
|
|
|
|
str[i] = '\0';
|
|
|
|
return str;
|
|
} |