- 166
- 7
- CPU
- Ryzen 5 1600 3.2GHz
- Scheda Madre
- MSI B350 Tomahawk
- HDD
- Seagate ST1000DM010 1 TB
- RAM
- 2X8GB Corsair CMK16GX4M2B3000C15 Vengeance
- GPU
- RADEON RX 580 NITRO+ Radeon RX 580 8GB GDDR5
- Monitor
- HP 27FW Monitor 27"
- PSU
- Cooler Master MasterWatt Lite 700 230V
- Case
- Aerocool Aero-800
- OS
- Windows 10
Salve, devo realizzare una funzione che dato un array di char S inverta l'ordine delle parole e con l'aiuto di un altro array di char Y trascriva la stringa finale in S e la stampi.
Con questo codice io faccio questo.
Per esempio se S é " Ciao come stai? "
La stringa Y sarà " ?iats emoc oaiC "
In seguito S sarà " Ciao come stai? "
Non ho capito per quale motivo, a volte non mi funziona per esempio quando alla fine del file c'è l'andata a capo.
Ecco il codice
Con questo codice io faccio questo.
Per esempio se S é " Ciao come stai? "
La stringa Y sarà " ?iats emoc oaiC "
In seguito S sarà " Ciao come stai? "
Non ho capito per quale motivo, a volte non mi funziona per esempio quando alla fine del file c'è l'andata a capo.
Ecco il codice
C++:
void yodizza(char S[], char Y[]) {
// Per calcolare la lunghezza si puo' fare cosi'
int lunghezza = strlen(S);
for( int i = 0; i/Ciclo che scrive l'intera stringa S al contrario in Y
{
Y[i] = S[lunghezza-1-i];
}
int wordstart, wordend, aux;
for( int i = 0; i {
wordstart = -1;
wordend = -1;
aux = -1;
if(Y[i]!=' ')
{
wordstart = i;
for( int j = wordstart; j {
if(Y[j]==' ')
{
wordend = j-1;
break;
}
}
if(wordend == -1) wordend = lunghezza-1;
} //L'if precedente serve a trovare la/le parola/e
else S[0+i] = ' ';
if(Y[i]!=' ')
{
aux = wordstart;
for( int k = wordend; k>=wordstart; k--,aux++)
{
S[aux] = Y[k];
}
i = wordend;
if (i+1 != lunghezza) S[i+1] = ' ';
}
}
}
[\CODE]