no save
Assistance
Achat
News

Forum | programmation
Langage C pointeurs, creation de liste.
Un Gars, le jeu. 30 mars 2006 à 16:03:05
Oui, vous avez raison :D

Donc voilà ce que j'ai fait (enfin j'avais fait autre choses en essayant de déclarer des fonctions etc ... mais il s'est effacé) :



#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LGTXT 256



typedef struct Fiche{
char Nom[256];
struct Fiche * Suivante;
}fiche;

typedef struct Maillon{
void * data;
struct Maillon * suite;
}maillon;

typedef struct Liste{
maillon * debut;
maillon * fin;
}liste;

//Creer une nouvelle liste
struct Liste nliste(){
struct Liste l;
l.debut=NULL;
l.fin=NULL;
return l;
}

Fiche*CreerFiche(char Texte[] )
{
//Obtenir le premier element
maillon * debut(struct Liste * l);
return l.debut;

//Obtenir le dernier element
maillon * fin(struct Liste * l);
return l.fin;

fiche* ptrfiche=(fiche*)malloc(sizeof(fiche));

//Inserer un élément en fin de liste
void add(struct liste * l,maillon * x){
maillon *m=l->fin();
if (m!=NULL) m->suite=x;
else l->debut=x;
l->fin=x;
}

struct maillon *m_it;
struct maillon *m_fin=l->fin();
for(m_it=l->debut() ; m_it!=m_fin ; m_it=m_it->Suivante)
{
//traiter le struct maillon courant (*m_it)
}


int main()
{
int arret;
char reponse[256];
fiche* ptrnouveau;
fiche* ptrdebut;
int nombre;

arret = 1;
ptrdebut = NULL;
ptrnouveau = NULL;
nombre = 0;

do{
printf("Entrer le nom de la fiche.\n\nEntrer ''Fin'' pour terminer le programme.\n\n");
gets (reponse);
printf("\n\n\n");
if (strcmp(reponse,"Fin"))
{
ptrnouveau = CreerFiche(reponse);
ptrnouveau->Suivante = ptrdebut;
ptrdebut = ptrnouveau;
nombre++;
}
else arret=0;
}while(arret);

if(nombre>1) printf("Vous avez cree %d fiches.",nombre);
else printf("Vous avez cree %d fiche.",nombre);

getchar();
}



return l.debut;


"l" undeclared identifier
left of '.debut' must have class/struct/union type




return l.fin;


left of '.fin' must have class/struct/union type
"l" identifier not found, even with argument-dependant lookup




void add(struct liste * l,maillon * x){
'add' : local function definitions are illegal




struct maillon *m_fin=l->fin();

left of'->fin' must point to class/struct/union type is "unknown-type"
"l" identifier not found, even with argument-dependant lookup




for(m_it=l->debut() ; m_it!=m_fin ; m_it=m_it->Suivante)

left of'->debut' must point to class/struct/union type is "unknown-type"
"l" identifier not found, even with argument-dependant lookup
use of undefined type '*(char[])CreerFiche::maillon'
left of'->Suivante' must point to class/struct/union




int main()
{

'main' : local function definitions are illegal




#include<stdio.h>

end of file found before the left brace '{' at bla bla bla




Voilà, j'ai sûrement dû mettre vos écrits un peu n'importe où, mais j'ai cherché où les mettre et pense que c'est ainsi qu'il faut faire ^^

Voilà, merci de votre aide ;)
Précédentmamiemando
mars 06
mamiemando
mars 06
Suivant
REPONSES
mamiemando
mars 06
Un Gars
mars 06
mamiemando
mars 06
Un Gars
mars 06
mamiemando
mars 06
Un Gars
mars 06
mamiemando
mars 06
Un Gars
mars 06
mamiemando
avr. 06
Drayell / Ank[58]f1x : Webmaster, Coder(C/C++, Asm), Designer
avr. 06
Version Web
Réalisé par RedShift
no save