|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Feb 2002
Messaggi: 906
|
[c++] strcpy()
faccio cose incredibili e mi perdo per le ca@@ate...
m_strStringa = (char *)malloc (512); ... assegno i char a m_strStringa e poi char ok[512]; strcpy(ok,m_strStringa[0]);//ERRORE!! m_strStringa contiene "i caratteri" e per scanzionarli uno ad uno mi serve inserirli nel char ok e poi tramite for leggerli uno ad uno facendo naturalmente strlen(ok);... ma non me lo permette il compilatore... error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *' oppure devo leggere un carattere alla volta di m_Stringa[0]; ...è da ridere eh? Ultima modifica di okay : 02-10-2006 alle 09:01. |
|
|
|
|
|
#2 | ||
|
Moderatore
Iscritto dal: Nov 2003
Messaggi: 16211
|
Quote:
Quote:
Non puoi chiamare strcpy su un char* e un char: devi chiamarla su due char*. P.S.: Hai la sign irregolare.
__________________
Ubuntu è un'antica parola africana che significa "non so configurare Debian" Scienza e tecnica: Matematica - Fisica - Chimica - Informatica - Software scientifico - Consulti medici REGOLAMENTO DarthMaul = Asus FX505 Ryzen 7 3700U 8GB GeForce GTX 1650 Win10 + Ubuntu |
||
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Feb 2002
Messaggi: 906
|
Quote:
strcpy(ok,m_Stringa[0]); questo è ancora errore... |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Nov 2003
Messaggi: 980
|
Devi cambiare il secondo parametro, non il primo: cannot convert parameter 2 from 'char' to 'const char *'
strcpy(ok, &m_Stringa[0]); che è lo stesso di strcpy(ok, m_Stringa); |
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Feb 2002
Messaggi: 906
|
Quote:
char ok[512]; m_strStringa = (char *)malloc (512); strcpy(ok, &m_strStringa[0]); perfetto grazie kk3z una cosa: cosa fà di preciso: (char *)malloc (512); ... e se invece usassi l'opratore new. Con l'operatore new otterrei lo stessa cosa di: m_strStringa = (char *)malloc (512); ? |
|
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
|
Quote:
dà lo stesso risultato di m_strStringa = (char *)malloc (512); L'unica cosa è che poi devi fare un delete m_strStringa; e non usare la free() della libreria "C".
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%) |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 03:58.



















