Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1063 connectés 

  FORUM HardWare.fr
  Programmation
  C

  Petite aide en C !

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Petite aide en C !

n°1950701
Ayag
Posté le 16-12-2009 à 08:38:30  profilanswer
 

Bonjour,
J'ai à réaliser un projet en informatique où l'on doit gérer des employés/chantiers/fournisseurs et clients en C, sous Linux.
J'ai donc crée un programme principal où l'on dispose d'un switch permettant de choisir si l'on veut aller dans la sous partie chantiers ou employés ou ..etc.
D'autre part, de manière séparée j'ai crée des "sous-fichiers" .c et .h pour chaque sous partie (employés, chantiers, ..).
Je voudrais que, lorsque l'utilisateur fait un choix dans le programme principal, il soit envoyé sur le programme crée dans les "sous-f-fichiers".
Or, je ne sais pas trop comment faire.
 
Chaque "sous-fichier" .c contient un #include "sous-fichier".h (correpondant bien sur).
 
Je ne sais pas si j'ai été très clair, je reste à l'affut si vous avez des questions pour éclairer mon propos.
Cordialement,
Ayag

mood
Publicité
Posté le 16-12-2009 à 08:38:30  profilanswer
 

n°1950746
ptitchep
Posté le 16-12-2009 à 10:02:54  profilanswer
 

Salut
 
sousFichier1.h:

Code :
  1. void fonctionSousFichier1();


sousFichier1.c

Code :
  1. #include "sousFichier1.h"
  2. void fonctionSousFichier1()
  3. {
  4.        printf ("fonctionSousFichier1\n" );
  5. }


sousFichier2.h:

Code :
  1. void fonctionSousFichier2();


sousFichier2.c

Code :
  1. #include "sousFichier2.h"
  2. void fonctionSousFichier2()
  3. {
  4.        printf ("fonctionSousFichier2\n" );
  5. }


main.c:

Code :
  1. #include "sousFichier1.h"
  2. #include "sousFichier2.h"
  3. int main()
  4. {
  5.      int choix;
  6.      //récupération du choix
  7.     switch (choix)
  8.     {
  9.     case FICHIER1:
  10.         fonctionSousFichier1();
  11.         break;
  12.     default:
  13.         fonctionSousFichier2();
  14.         break;
  15.     }
  16. }


 
Je réponds à la question?


Message édité par ptitchep le 16-12-2009 à 10:18:24

---------------
deluser --remove-home ptitchep
n°1950756
olivthill
Posté le 16-12-2009 à 10:13:59  profilanswer
 

Exemple :
 
Fichier principal toto.c :

extern int fonction_dans_titi(double num);
 
static int fonction_dans_toto(char *nom)
{
  printf(nom);
  return 0;
}
 
int main(int argc, char *argv[])
{
   int return_code;
   int choix;
 
   for (;;) {
 
      //récupération du choix (à programmger avec scanf ou autre chose)
 
      switch (choix)
      {
       case 1:
          return_code = fonction_dans_toto("abc" );
          if (return_code != 0) exit (return_code);
          break;
       case 2:
          return_code = fonction_dans_titi(123.00);
          if (return_code != 0) exit (return_code);
          break;
       default:
          exit(0);
          break;
       }
   }
   exit(0);
}


 
Fichier secondaire titi.c :

int fonction_dans_titi(double num)
{
  printf("%f", num);
  return 0;
}

Edit: grilled, mais mon exemple est un peu différent alors c'est complémentaire.


Message édité par olivthill le 16-12-2009 à 10:32:34
n°1950876
Ayag
Posté le 16-12-2009 à 13:25:18  profilanswer
 

Okay merci de vos réponses je vais aller essayer ca !


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C

  Petite aide en C !

 

Sujets relatifs
Aide applet java niveau débutantBesoin d'aide en VBA
[C] Programme simpleAide pour un programme python
Projet Algo CProjet C
Besoin d'aide pour la programmation d'un menu en htmlBesoin d'aide pour un escalier
Plus de sujets relatifs à : Petite aide en C !


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR