hi;


I find probleme is that the result of run not be saved in the file ;
the second things that I m very sad because I work for 2 weeks and I can't up to now to do the programme;
the programme is;


we have class called A in A there are two classes B et C in B and C many classes , for each one there are many people ; how I can use struct to define that strcut ?
and I should to do all operator of add,erase , searche,


a

#include"def2.h"
#define ESC 27

char menu(){
     printf("\tVous etes sur le menu,veuillez choisir une fonction parmis les 2 choix:");
     printf("\n\t1- Insertion d'un adherent");
     printf("\n\t2- Afficher tous les adherents");
     printf("\n\tPour quitter le programme, appuyez sur ESC. \n");
     return (getch());
} 

void inserer(data d){
     adherent * p = Malloc(adherent);
     p->d = d;
     p->suivant = premier ;
     premier = p;
     }  
     
    

void choice(){
     char choix = menu();
     data d;
     char nom[20];char prenom[10];char adresse[50];int num_unique;
     switch(choix){
                   case '1' : printf("\ndonner le nom de l'adherent :");
                              scanf("%s",&d.nom);
                              printf("\ndonner le prenom :");
                              scanf("%s",&d.prenom); 
                              printf("\ndonner l'adresse : ");                   
                              scanf("%s",&d.adresse);
                              d.num_unique=add();
                              inserer(d);
                              system("cls");
                              choice();
                              break;
                   case '2' : parcours();
                              getch();
                              system("cls");
                              choice();
                              break;
                   case 27 : quitter();
                   }              
}


  
void quitter(){
     sauvegarder();
     exit(1);
}


     
void parcours(){data d;
     adherent * p;
     if(premier == NULL) printf("il n'y a pas de congressiste inscrit\n");
     p = premier;
     while(p != NULL){
             d = p->d;
             printf("\n identifiant:\t%d \nnom:\t%s \nprenom:\t%s \nadresse:\t%s\n\n",d.num_unique,d.nom,d.prenom,d.adresse);
             p = p->suivant;
             }
}             
                
void charger(){
     FILE *f = fopen("adherent.dta","a");
     if(f == NULL) return;
     //lire les donnees du fichier vers la memoire
     while(!feof(f)){
                     data d;
                     fread(&d,sizeof(d),1,f);
                     inserer(d);
                     }
     fclose(f);
     }
void sauvegarder(){
     adherent *p;
     //vers le fichier
     FILE *f = fopen("adherent.dta","w");
     if(f == NULL) return;
     //sauvegarder adherent par adh
     p=premier;
     while(p != NULL){data d;
                fwrite(&p->d,sizeof(d),1,f);
                p=p->suivant;
                }
     fclose(f);
     }

Recommended Answers

All 3 Replies

Here's some important things to do:

1) This is predominately an English language board. Translate your program into English, and re-post it.

2) In the advanced edit window, highlight your code and click on the [code/b]/b word at the top of the edit window. That will make your program look like a program.

3) use good indentation. Just two to five spaces between levels of code, is a HUGE help to spot errors, quickly and easily. Tabs are not preferred, but one is OK.

4) delete the 'a' before your first include file, and where is your standard include files, like string.h or stdio.h and maybe stdlib.h?

We can help with your program, but my French is on holiday.

Here's some important things to do:

1) This is predominately an English language board. Translate your program into English, and re-post it.

That's not a requirement for getting help here. The post was made in as good English as the OP could produce. The code doesn't have to be in English.
The reason why it may not get enough help is because it did not use the proper code tagging protocol and is hard to read as code goes, not because the literal strings are in French.


@OP
There's not such a function named Malloc() in the standard C. malloc() with low case is the correct one.

The code you posted is fragmented.
It is not possible to know (just guess) what objects like adherent and premier are.
We see member of structures or unions but we don't see definitions anywhere.

This is an example of your problem:

void inserer(data d){
adherent * p = malloc(adherent); /* what's adherent */
p->d = d;
p->suivant = premier ; /* where does premier come from? */
premier = p; /* how could premier point to p if we don't know where it come from and what it is? */
}

A lot of work that produce nothing, since any work done has only local scope withing the function inserer(). Once it is finished, the values are gone or lost. The memory allocated with malloc() can not be used because the pointer is lost, and that memory is in `leak' realm.

i've reconstructed this in in my text editor and fixed the indentations, and it's not terribly hard to read.

but we will need that "def2.h" file. I'll bet that's where all the missing info is that Aia is asking about

i was going to note that i don't see any reference being made to the "charger()" function (translate "load") but then i also don't see a "main()" function. where is main()?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.