Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Recensione HUAWEI Mate X7: un foldable ottimo, ma restano i soliti problemi
Recensione HUAWEI Mate X7: un foldable ottimo, ma restano i soliti problemi
Mate X7 rinnova la sfida nel segmento dei pieghevoli premium puntando su un design ancora più sottile e resistente, unito al ritorno dei processori proprietari della serie Kirin. L'assenza dei servizi Google e del 5G pesa ancora sull'esperienza utente, ma il comparto fotografico e la qualità costruttiva cercano di compensare queste mancanze strutturali con soluzioni ingegneristiche di altissimo livello
Nioh 3: souls-like punitivo e Action RPG
Nioh 3: souls-like punitivo e Action RPG
Nioh 3 aggiorna la formula Team NINJA con aree esplorabili più grandi, due stili di combattimento intercambiabili al volo (Samurai e Ninja) e un sistema di progressione pieno di attività, basi nemiche e sfide legate al Crogiolo. La recensione entra nel dettaglio su combattimento, build, progressione e requisiti PC
Test in super anteprima di Navimow i220 LiDAR: il robot tagliaerba per tutti
Test in super anteprima di Navimow i220 LiDAR: il robot tagliaerba per tutti
La facilità di installazione e la completa automazione di tutte le fasi di utilizzo, rendono questo prodotto l'ideale per molti clienti. Ecco com'è andata la nostra prova in anteprima
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 26-03-2012, 18:31   #1
Joker91
Senior Member
 
Iscritto dal: Feb 2007
Messaggi: 467
[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, 19: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, 19: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, 20:15   #4
Joker91
Senior Member
 
Iscritto dal: Feb 2007
Messaggi: 467
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 20:33.
Joker91 è offline   Rispondi citando il messaggio o parte di esso
Old 26-03-2012, 20: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, 22: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 27-03-2012, 00: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 HUAWEI Mate X7: un foldable ottimo, ma restano i soliti problemi Recensione HUAWEI Mate X7: un foldable ottimo, m...
Nioh 3: souls-like punitivo e Action RPG Nioh 3: souls-like punitivo e Action RPG
Test in super anteprima di Navimow i220 LiDAR: il robot tagliaerba per tutti Test in super anteprima di Navimow i220 LiDAR: i...
Dark Perk Ergo e Sym provati tra wireless, software via browser e peso ridotto Dark Perk Ergo e Sym provati tra wireless, softw...
DJI RS 5: stabilizzazione e tracking intelligente per ogni videomaker DJI RS 5: stabilizzazione e tracking intelligent...
Sembra ormai certo: la prossima Xbox sar...
“Solutions Beyond Displays”: la strategi...
La società europea The Exploratio...
Dalle auto ai robot umanoidi: Faraday Fu...
Vodafone annuncia la dismissione di un s...
Stiga lancia i nuovi robot tagliaerba co...
Bullismo e cyberbullismo, Keenetic lanci...
Con AI Skills Checker Bitdefender mette ...
E-bike giapponese con 1.000 km di autono...
Un eVTOL con cui basta saper andare in b...
Dal mercato cinese al mondo: HONOR firma...
Sovranità digitale: l'UE sperimen...
Accesso alla memoria su Windows 11 solo ...
iPhone 18 Pro Max con batteria da oltre ...
Windows 11, cali di prestazioni sulle GP...
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: 05:38.


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