Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Recensione HONOR Magic V6: spessore record e super batteria. È lui il fold da battere?
Recensione HONOR Magic V6: spessore record e super batteria. È lui il fold da battere?
HONOR Magic V6 è arrivato in Italia a 2.299,90 euro con una promessa precisa: unire 4 mm di spessore da aperto (8,75 mm chiuso nel modello White, 9 mm negli altri colori) a una batteria da 6.660 mAh, la più capiente mai vista su un pieghevole. Lo abbiamo usato per oltre una settimana in versione Red 16/512 GB per capire se lo Snapdragon 8 Elite Gen 5 tiene testa alla concorrenza anche fuori dai benchmark ufficiali
Redmi Pad 2 9.7: ampio display, economico e peso contenuto, ma qualche limite nelle prestazioni
Redmi Pad 2 9.7: ampio display, economico e peso contenuto, ma qualche limite nelle prestazioni
Redmi Pad 2 9.7 punta su un display ampio e fluido, una batteria capace di accompagnare l'uso quotidiano senza ansie da ricarica e un prezzo accessibile, a partire da 179,90 euro per la versione con 64 GB di storage. Lo Snapdragon 6s 4G Gen 2 e i 4 GB di RAM della configurazione più diffusa frenano però chi cerca reattività e multitasking spinto: ecco il bilancio dopo due settimane di prova diretta
Peugeot Polygon Concept: ecco il futuro delle utilitarie
Peugeot Polygon Concept: ecco il futuro delle utilitarie
Polygon è la concept car di Peugeot che mostra il futuro delle soluzioni del segmento B: tra design compatti e innovativi affiancati da dimensioni compatte uno scherzo dalla manovrabilità incredibile per le manovre a bassa velocità
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 26-03-2012, 17:31   #1
Joker91
Senior Member
 
Iscritto dal: Feb 2007
Messaggi: 468
[C] strtok e qsort

ho dei problemi quando vado a compilare il programma (usando -Wall), ve li elenco così magari qualcuno riesce a dirmi il problema...

- Il primo esce quando uso la funzione strtok di string.h, in questo modo:

Codice:
tok = strtok(p, ';');
passing argument 2 of ‘strtok’ makes pointer from integer without a cast [enabled by default]
/usr/include/string.h:348:14: note: expected ‘const char * __restrict__’ but argument is of type ‘int’


Mi pare di capire che legge il punto e virgola come intero invece che come carattere?

- Il secondo problema è quando uso il qsort, sto facendo sicuramente qualche errore con il casting... l'errore precisamente è nella funzione di comparazione che ho definito così:

Codice:
int cmpautore(const void *p1, const void *p2) {
	
	int n;
	if (n= cmpstringp(*(scheda_t*)p1->autore->cognome, *(scheda_t*)p2->autore->cognome) != 0) return n;
	return cmpstringp(*(scheda_t*)p1->autore->nome, *(scheda_t*)p2->autore->nome);
}

warning: dereferencing ‘void *’ pointer [enabled by default]
error: request for member ‘autore’ in something not a structure or union


scheda_t è una struttura, autore è un puntatore a struttura dentro scheda_t...

cioè

Codice:
typedef scheda{
  autore_t* autore;} scheda_t;
p1 e p2 che passo nella compare sono appunto due puntatori a scheda_t
Joker91 è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2012, 18:26   #2
clockover
Senior Member
 
L'Avatar di clockover
 
Iscritto dal: Oct 2004
Messaggi: 1945
Per strtok devi usare i doppi apici nel definire il separatore http://www.manpagez.com/man/3/strtok/ , per l 'altro problema non riesco a leggere bene dato che sono con il cellulare
clockover è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2012, 18:30   #3
clockover
Senior Member
 
L'Avatar di clockover
 
Iscritto dal: Oct 2004
Messaggi: 1945
Prova così
((Scheda_t*)p1)->autore
clockover è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2012, 19:15   #4
Joker91
Senior Member
 
Iscritto dal: Feb 2007
Messaggi: 468
così mi toglie quel warning ma mi dà questo che comunque non è grave:

warning: suggest parentheses around assignment used as truth value


però ho un altro problema, e cioè che devo fare una funzione compare per la qsort fra le struct scheda_t usando un loro valore numerico all'interno... E anche qui ho qualche problema col casting... Ecco cos'ho scritto io:



Codice:
RIGA 611: int cmpnumero(const void *p1, const void *p2){
	return (*(int*)p1 - *(int*)p2);
}

int cmpprestito(const void *p1, const void *p2){
	int n;
	
	if (n= cmpnumero(((scheda_t*)p1)->prestito.scadenza.tm_year, ((scheda_t*)p2)->prestito.scadenza.tm_year) != 0) return n;
	if (n= cmpnumero(((scheda_t*)p1)->prestito.scadenza.tm_mon, ((scheda_t*)p2)->prestito.scadenza.tm_mon) != 0) return n;
	return cmpnumero(((scheda_t*)p1)->prestito.scadenza.tm_mday, ((scheda_t*)p2)->prestito.scadenza.tm_mday);
RIGA 621: }

"cmpnumero" non è altro che la compare fra interi... Alla fine il concetto dovrebbe essere lo stesso del primo esempio, semplicemente qui ho degli interi e lì una stringa. Però mi dà errori diversi:


bib.c: In function ‘cmpprestito’:
bib.c:618:2: warning: passing argument 1 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:618:2: warning: passing argument 2 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:618:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
bib.c:619:2: warning: passing argument 1 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:619:2: warning: passing argument 2 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:619:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
bib.c:620:2: warning: passing argument 1 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:620:2: warning: passing argument 2 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c: In function ‘ricerca_tag’:
bib.c:657:1: warning: control reaches end of non-void function [-Wreturn-type]

Ultima modifica di Joker91 : 26-03-2012 alle 19:33.
Joker91 è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2012, 19:50   #5
clockover
Senior Member
 
L'Avatar di clockover
 
Iscritto dal: Oct 2004
Messaggi: 1945
Sempre perché non riesco a leggere bene non posso correggerti direttamente ma questo link dovrebbe aiutarti
http://gcc.gnu.org/ml/gcc/1998-07/msg00085.html
clockover è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2012, 21:24   #6
pabloski
Senior Member
 
Iscritto dal: Jan 2008
Messaggi: 8406
Vorrei chiarire il perchè nel primo caso si comportava così. Quando usi gli apici singoli ( mettendo tra di essi un singolo carattere ) stai in realtà passando un tipo char, cioè un valore numerico. Lo so si chiama char, ma in realtà è un numero non una stringa di un solo elemetno.

Stesso discorso vale nel secondo caso, solo che lì hai messo come parametri d'input 2 puntatori ma poi gli passi degli interi?

In pratica prima fai un passaggio per riferimento/puntatore e poi passi il parametro per valore? E' un erroraccio!!!
pabloski è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2012, 23:42   #7
clockover
Senior Member
 
L'Avatar di clockover
 
Iscritto dal: Oct 2004
Messaggi: 1945
Quote:
Originariamente inviato da Joker91 Guarda i messaggi
così mi toglie quel warning ma mi dà questo che comunque non è grave:

warning: suggest parentheses around assignment used as truth value


però ho un altro problema, e cioè che devo fare una funzione compare per la qsort fra le struct scheda_t usando un loro valore numerico all'interno... E anche qui ho qualche problema col casting... Ecco cos'ho scritto io:



Codice:
RIGA 611: int cmpnumero(const void *p1, const void *p2){
	return (*(int*)p1 - *(int*)p2);
}

int cmpprestito(const void *p1, const void *p2){
	int n;
	
	if (n= cmpnumero(((scheda_t*)p1)->prestito.scadenza.tm_year, ((scheda_t*)p2)->prestito.scadenza.tm_year) != 0) return n;
	if (n= cmpnumero(((scheda_t*)p1)->prestito.scadenza.tm_mon, ((scheda_t*)p2)->prestito.scadenza.tm_mon) != 0) return n;
	return cmpnumero(((scheda_t*)p1)->prestito.scadenza.tm_mday, ((scheda_t*)p2)->prestito.scadenza.tm_mday);
RIGA 621: }

"cmpnumero" non è altro che la compare fra interi... Alla fine il concetto dovrebbe essere lo stesso del primo esempio, semplicemente qui ho degli interi e lì una stringa. Però mi dà errori diversi:


bib.c: In function ‘cmpprestito’:
bib.c:618:2: warning: passing argument 1 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:618:2: warning: passing argument 2 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:618:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
bib.c:619:2: warning: passing argument 1 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:619:2: warning: passing argument 2 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:619:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
bib.c:620:2: warning: passing argument 1 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c:620:2: warning: passing argument 2 of ‘cmpnumero’ makes pointer from integer without a cast [enabled by default]
bib.c:611:5: note: expected ‘const void *’ but argument is of type ‘int’
bib.c: In function ‘ricerca_tag’:
bib.c:657:1: warning: control reaches end of non-void function [-Wreturn-type]
per trovare gli errori dovresti postare almeno tutte le tue struct...
clockover è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Recensione HONOR Magic V6: spessore record e super batteria. È lui il fold da battere? Recensione HONOR Magic V6: spessore record e sup...
Redmi Pad 2 9.7: ampio display, economico e peso contenuto, ma qualche limite nelle prestazioni Redmi Pad 2 9.7: ampio display, economico e peso...
Peugeot Polygon Concept: ecco il futuro delle utilitarie Peugeot Polygon Concept: ecco il futuro delle ut...
Reno16 Pro: il compatto di OPPO punta su fotocamera da 200MP e il nuovo Bubble! La recensione Reno16 Pro: il compatto di OPPO punta su fotocam...
 Hisense 55U7SE: tuttofare e accessibile, il MiniLED per film, sport e gioco Hisense 55U7SE: tuttofare e accessibile, il Min...
Chrome espone l'OS reale dietro ogni ric...
Intel investe altri 5 miliardi di euro p...
OPPO sceglie Clara per il debutto della ...
Migliori offerte sui robot aspirapolvere...
Nuove funzionalità per Network Se...
Come un'auto che non ha mai visto la str...
Nel calcio dei robot vince solo Booster:...
Windows 11, smartphone e PC sono sempre ...
Account Xbox bloccato e giochi persi. Mi...
Apple M7 Ultra: in arrivo nel 2027 con b...
Le auto autonome ostacolano ambulanze e ...
Steam Machine, LED rosso e falsi positiv...
SharpEmu, nuovo emulatore PlayStation 5 ...
Sovranità sui dati: Oracle AI Dat...
Monopattini, scatta l'obbligo di assicur...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 14:01.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v