Torna indietro   Hardware Upgrade Forum > Software > Programmazione

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
Dark Perk Ergo e Sym provati tra wireless, software via browser e peso ridotto
Dark Perk Ergo e Sym provati tra wireless, software via browser e peso ridotto
be quiet! debutta nel settore mouse da gaming con Dark Perk Ergo e Dark Perk Sym: due modelli gemelli per specifiche, con polling rate di 8.000 Hz anche in wireless, sensore PixArt PAW3950 da 32.000 DPI e autonomia dichiarata fino a 110 ore. Nel test, a 8.000 Hz si arriva a circa 30 ore reali, con ricarica completa in un'ora e mezza
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


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...
AMD Ryzen 7 9850X3D: Zen 5, 3D V-Cache e frequenze al top per il gaming AMD Ryzen 7 9850X3D: Zen 5, 3D V-Cache e frequen...
Il telescopio XRISM ha osservato i raggi...
Il telescopio spaziale James Webb ha sco...
Logitech G325: audio di fascia alta, wir...
Nessuna pubblicità su Claude, per...
Gli stipendi nel settore tech? Sono anco...
Problemi con la stampa 3D? Un prompt per...
Amazon Leo amplia i contratti con SpaceX...
Basta Purefication, il Giurì bloc...
LibreOffice 26.2 migliora prestazioni e ...
La Cina si prepara a un test della capsu...
La NASA rende note alcune informazioni a...
ASUS ExpertCenter PN54: mini PC Copilot+...
Geely userà una fabbrica europea ...
Leica Camera tratta la cessione della ma...
La nuova AMD non è più 'ec...
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: 22:49.


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