Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Algoritmi e strutture dati > [PROGETTO] "Mappe 2" Thread Rating: 1 votes, 5.00 average.
Pages (17): « 1 2 3 4 [5] 6 7 8 9 » ... Last »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
MaurizioL
.simpatizzante.

User info:
Registered: Feb 2006
Posts: 17 (0.00 al dì)
Location: Omegna
Corso: Informatica
Anno: 2
Time Online: 3:44:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Diuzza
typedef struct nodolista{
char spec;
struct nodolista* next;
}nodo

typedef struct lista{
nodo* inizio;
nodo* fine;
}lista

typedef struct mappa{
lista* specifica;
int x,y;
char * nome;
}
no?


Sì, per funzionare funziona, ma non vedo perchè usare due strutture per rappresentare un vettore di char.
Comunque se a te piace...

Secondo me faresti meglio a concentrarti su altri problemi (tipo come memorizzare le mappe in modo efficiente).

__________________
Maurizio Lombardi
Linux 2.6.14.2
-----------------------

09-02-2006 16:06
Click Here to See the Profile for MaurizioL Click here to Send MaurizioL a Private Message Find more posts by MaurizioL Add MaurizioL to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Simeon
:D

User info:
Registered: Aug 2004
Posts: 984 (0.13 al dì)
Location: Milano
Corso: Informatica
Anno: IT IS OVER!
Time Online: 14 Days, 19:29:42 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Diuzza
Ho visto il codice di prima ma creo un array char nome[100] per magari inserire solo 4 caratteri.


Io ho fatto una realloc per ogni singolo carattere, forse ho esagerato :asd:, ma per stringhe corte va piu che bene.

Basta adattare i "salti" a seconda delle situazioni...

Edit : in effetti manco io capisco perche usare delle strutture per memorizzare le specifiche

Last edited by Simeon on 09-02-2006 at 16:26

09-02-2006 16:23
Click Here to See the Profile for Simeon Click here to Send Simeon a Private Message Find more posts by Simeon Add Simeon to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
MaurizioL
.simpatizzante.

User info:
Registered: Feb 2006
Posts: 17 (0.00 al dì)
Location: Omegna
Corso: Informatica
Anno: 2
Time Online: 3:44:01: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Diuzza
Ho visto il codice di prima ma creo un array char nome[100] per magari inserire solo 4 caratteri.


Puoi mettere quanto vuoi, io ho messo 100 solo perchè avevo fatto qualche prova;
20 dovrebbero essere sufficienti.

__________________
Maurizio Lombardi
Linux 2.6.14.2
-----------------------

09-02-2006 17:03
Click Here to See the Profile for MaurizioL Click here to Send MaurizioL a Private Message Find more posts by MaurizioL Add MaurizioL to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Simeon
:D

User info:
Registered: Aug 2004
Posts: 984 (0.13 al dì)
Location: Milano
Corso: Informatica
Anno: IT IS OVER!
Time Online: 14 Days, 19:29:42 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ragazzi io userei un albero di ricerca binario anche per memorizzare le mappe... con tutte le operazioni di ricerca che vengono richieste mi pare adatto.

Ordinandole lessicograficamente per il nome.

09-02-2006 17:17
Click Here to See the Profile for Simeon Click here to Send Simeon a Private Message Find more posts by Simeon Add Simeon to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ornati
.primate.

User info:
Registered: Apr 2005
Posts: 78 (0.01 al dì)
Location:
Corso: Informatica
Anno: 3
Time Online: 21:49:35 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Diuzza
Mi chiedevo.
In crea il nome del file ha lunghezza che fisso io o può essere lungo quanto vuole. Perchè avrei dei problemini nella lettura del file. Nel senso che se non ho una lunghezza fissata non so che dimensione deve avere l'arrey che contiene la stringa


Il problema è sempre lo stesso (= a quello di memorizzare una specifica). La soluzione è:

1) usare un puntatore ad un'area di memoria allocata dinamicamente
2) usare malloc/realloc per allocare/espandere

Ecco un piccolo programma dimostrativo:

code:
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> char *read_token(FILE *f) { char *buf; int size = 16; int len = 0; int c; buf = malloc(size); while ((c=getc(f)) != EOF) { if (!isalnum(c)) { if (len == 0) continue; break; } if (len+1 >= size) { size <<= 1; /* size = size * 2 */ buf = realloc(buf, size); } buf[len++] = c; } buf[len++] = '\0'; buf = realloc(buf, len); return buf; } int main(void) { char *x; int run = 1; while (run) { x = read_token(stdin); printf("letto token <%s>\n", x); if (strcmp("end", x) == 0) run = 0; free(x); }; return 0; }

09-02-2006 17:42
Click Here to See the Profile for ornati Find more posts by ornati Add ornati to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Diuzza
.illuminato.

User info:
Registered: Aug 2004
Posts: 169 (0.02 al dì)
Location:
Corso: Informatica
Anno: 2
Time Online: 1 Day, 8:30:45 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ho già risolto. Ma sarò gnucca ma ho un altro problema.

Possibile che quando cerco di accedere ad un file il mio sistema mi dice che si è verificato un errore, potrebbe esserci la perdita dei dati su cui sto lavorando... ?

09-02-2006 17:44
Click Here to See the Profile for Diuzza Click here to Send Diuzza a Private Message Find more posts by Diuzza Add Diuzza to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ornati
.primate.

User info:
Registered: Apr 2005
Posts: 78 (0.01 al dì)
Location:
Corso: Informatica
Anno: 3
Time Online: 21:49:35 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Diuzza
Ho già risolto. Ma sarò gnucca ma ho un altro problema.

Possibile che quando cerco di accedere ad un file il mio sistema mi dice che si è verificato un errore, potrebbe esserci la perdita dei dati su cui sto lavorando... ?


Strano... non mi è mai successa una cosa simile...
prova a postare il codice che ti dà problemi.

Last edited by ornati on 09-02-2006 at 17:58

09-02-2006 17:52
Click Here to See the Profile for ornati Find more posts by ornati Add ornati to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Ari_85
.amico.

User info:
Registered: Aug 2005
Posts: 31 (0.00 al dì)
Location: Omegna
Corso: Informatica
Anno: 2
Time Online: 10:45:16 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Se creiamo un albero per le mappe e un albero per i punti dovremo creare due alberi separati nel senso che dovremo scrivere due volte il codice perchè ad es la f inserisci del primo albero è diversa da quella del secondo perchè lavorano su nodi diversi..Certo, ci si guadagna in tempo di calcolo...
Ciao Lomba!

__________________
Good wombs hath borne bad sons

09-02-2006 17:57
Click Here to See the Profile for Ari_85 Click here to Send Ari_85 a Private Message Find more posts by Ari_85 Add Ari_85 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ornati
.primate.

User info:
Registered: Apr 2005
Posts: 78 (0.01 al dì)
Location:
Corso: Informatica
Anno: 3
Time Online: 21:49:35 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Ari_85
Se creiamo un albero per le mappe e un albero per i punti dovremo creare due alberi separati nel senso che dovremo scrivere due volte il codice perchè ad es la f inserisci del primo albero è diversa da quella del secondo perchè lavorano su nodi diversi..Certo, ci si guadagna in tempo di calcolo...
Ciao Lomba!


Non è detto... guarda per esempio la mia Hash_Table, c'è una sola implementazione e viene usata per inserire cose diverse (perchè usa internamente puntatori "void*").

L'unico problema dei puntatori "void*" è che perdi il controllo sui tipi dato dal compilatore.

Last edited by ornati on 09-02-2006 at 18:17

09-02-2006 18:05
Click Here to See the Profile for ornati Find more posts by ornati Add ornati to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Diuzza
.illuminato.

User info:
Registered: Aug 2004
Posts: 169 (0.02 al dì)
Location:
Corso: Informatica
Anno: 2
Time Online: 1 Day, 8:30:45 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

ho un char* nome

faccio
int c;
FILE * valpunti;
valpunti=fopen(nome, "r");
fscanf(valpunti,"%d",&c);


magari ho fatto io qualche s....

09-02-2006 18:25
Click Here to See the Profile for Diuzza Click here to Send Diuzza a Private Message Find more posts by Diuzza Add Diuzza to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ornati
.primate.

User info:
Registered: Apr 2005
Posts: 78 (0.01 al dì)
Location:
Corso: Informatica
Anno: 3
Time Online: 21:49:35 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Diuzza
ho un char* nome

faccio
int c;
FILE * valpunti;
valpunti=fopen(nome, "r");
fscanf(valpunti,"%d",&c);


magari ho fatto io qualche s....


Sembra corretto.

Prova a mettere un controllo sulla "fopen":

code:
valpunti = fopen(nome, "r"); if (valpunti == NULL) { printf("Errore: impossibile aprire '%s'\n", nome); exit(1); }

09-02-2006 19:05
Click Here to See the Profile for ornati Find more posts by ornati Add ornati to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Dav83
.amico.

User info:
Registered: Jun 2003
Posts: 36 (0.00 al dì)
Location: Casorate Primo
Corso: Informatica
Anno: 3
Time Online: 15:52:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

in alternativa si può usare la 'fread' che legge parte del file(indicato dai parametri)...http://www.cplusplus.com/ref/cstdio/fread.html

__________________
Ciao miao bau

10-02-2006 00:15
Click Here to See the Profile for Dav83 Click here to Send Dav83 a Private Message Find more posts by Dav83 Add Dav83 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Dav83
.amico.

User info:
Registered: Jun 2003
Posts: 36 (0.00 al dì)
Location: Casorate Primo
Corso: Informatica
Anno: 3
Time Online: 15:52:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

in alternativa si può usare la 'fread' che legge parte del file(indicato dai parametri)...http://www.cplusplus.com/ref/cstdio/fread.html

__________________
Ciao miao bau

10-02-2006 00:15
Click Here to See the Profile for Dav83 Click here to Send Dav83 a Private Message Find more posts by Dav83 Add Dav83 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
ornati
.primate.

User info:
Registered: Apr 2005
Posts: 78 (0.01 al dì)
Location:
Corso: Informatica
Anno: 3
Time Online: 21:49:35 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Dav83
in alternativa si può usare la 'fread' che legge parte del file(indicato dai parametri)...http://www.cplusplus.com/ref/cstdio/fread.html


In alternativa a cosa?

10-02-2006 07:23
Click Here to See the Profile for ornati Find more posts by ornati Add ornati to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Diuzza
.illuminato.

User info:
Registered: Aug 2004
Posts: 169 (0.02 al dì)
Location:
Corso: Informatica
Anno: 2
Time Online: 1 Day, 8:30:45 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

No mi va fino alla fopen perchè ho messo un fprint dopo e stampa quindi lì' ci arriva..
non mi va la fscanf. moh

10-02-2006 09:06
Click Here to See the Profile for Diuzza Click here to Send Diuzza a Private Message Find more posts by Diuzza Add Diuzza to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 10:58.    Post New Thread    Post A Reply
Pages (17): « 1 2 3 4 [5] 6 7 8 9 » ... Last »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.123 seconds (74.91% PHP - 25.09% MySQL) con 26 query.