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