Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define max_champs 25
  5. #define lgMot 30
  6. #define lgMax 80
  7. #define max_data 20
  8. #define max_enr 100
  9. #pragma warning (disable:4996)
  10.  
  11. /*Définition des structures de données :*/
  12.  
  13. typedef struct {
  14.     char nom[lgMot + 1];
  15.     char type[lgMot + 1];
  16. } Champ; //Déclaration d'un nouveau type de variable structurée qui correspond au champ utilisé dans la table
  17.  
  18. typedef struct {
  19.     char nomData[lgMot + 1];
  20. } Data; //Déclaration d'un nouveau type de variable structurée qui correspond aux données ajoutées
  21.  
  22. typedef struct {
  23.     Data numData[max_data];
  24. } Enregistrement;
  25.  
  26. typedef struct {
  27.     char nom[lgMot + 1];
  28.     Champ schema[max_champs];
  29.     unsigned char nbChamps;
  30.     Enregistrement Enregistrement[max_enr];
  31.     unsigned char nombreEnregistrement;
  32. } Table; //Déclaration d'un nouveau type de variable structurée qui correspond à la table
  33.  
  34. void Afficher_enregistrements(Table* t);
  35. void Create_table(Table* t);
  36. void Afficher_shema(Table* t);
  37. void Insert_enregistrement(Table* t);
  38. void Delete_enregistrement(Table* t);
  39. void Afficher_enregistrement(Table* t);
  40. void Delete_table(Table* t);
  41. void Select_enregistrement(Table* t);
  42. void compare_enregistrement(Table* t,int i);
  43.  
  44. /*Programme principal*/
  45.  
  46. int main() {
  47.     Champ c;
  48.     Table t;
  49.     t.nombreEnregistrement = 0;
  50.     char choix[lgMot];
  51.     strcpy(t.nom, "");//char nom_table[lgMot] = "";
  52.  
  53.     while (1) {
  54.         scanf("%s", choix);//choix utilisateur
  55.         if (strcmp(choix, "Create_table") == 0) {
  56.             Create_table(&t);
  57.         }
  58.         if (strcmp(choix, "Afficher_schema") == 0) {
  59.             Afficher_shema(&t);
  60.         }
  61.         if (strcmp(choix, "Insert_enregistrement") == 0) {
  62.             Insert_enregistrement(&t);
  63.         }
  64.         if (strcmp(choix, "Afficher_enregistrements") == 0) {
  65.             Afficher_enregistrements(&t);
  66.         }
  67.         if (strcmp(choix, "Delete_enregistrement") == 0) {
  68.             Delete_enregistrement(&t);
  69.         }
  70.         if (strcmp(choix, "Afficher_enregistrement") == 0) {
  71.             Afficher_enregistrement(&t);
  72.         }
  73.         if (strcmp(choix, "Delete_table") == 0) {
  74.             Delete_table(&t);
  75.         }
  76.         if (strcmp(choix, "Select_enregistrement") == 0) {
  77.             Select_enregistrement(&t);
  78.         }
  79.         if (strcmp(choix, "Exit") == 0) {
  80.             exit(0);
  81.         }
  82.  
  83.     }
  84.     system("pause"); return 0;
  85. }
  86.  
  87. /*Déclaration des différentes fonctions :*/
  88. void compare_enregistrement(Table* t,int i) {
  89.     char choix1[lgMot + 1], choix2[lgMot + 1];                          //introduction d'une variable texte dans la fonction create table
  90.     scanf("%s", &choix1);
  91.     scanf("%s", &choix2);
  92.     if (strcmp(t->schema[i].nom, "TEXT")==0) {
  93.  
  94.  
  95.     }
  96.     if (strcmp(t->schema[i].nom, "INT") == 0) {
  97.  
  98.     }
  99.     if (strcmp(t->schema[i].nom, "FLOAT") == 0) {
  100.  
  101.     }
  102.      if (strcmp(t->schema[i].nom, "DATE") == 0) {
  103.  
  104.     }
  105. }
  106.  
  107. void Select_enregistrement(Table* t){
  108.     char choix[lgMot + 1];                          //introduction d'une variable texte dans la fonction create table
  109.     scanf("%s", &choix);
  110.     if (strcmp(choix, t->nom) != 0) {
  111.         printf("table inconnue");
  112.         return;
  113.     }
  114.     scanf("%s", choix);
  115.     for (int i = 0; t->nbChamps; ++i) {
  116.         if (strcmp(t->schema[i].nom, choix)==0) {
  117.             compare_enregistrement(&t,i);
  118.         }
  119.     }
  120.  
  121. }
  122. void compare_enregistrement(Table* t) {
  123.  
  124. }
  125.  
  126. void Create_table(Table* t) {
  127.     char choix[lgMot + 1];                          //introduction d'une variable texte dans la fonction create table
  128.     if (strcmp(t->nom, "") != 0) {                  //vérifie s'il existe une table déjà présente, si il y en a déjà une, refuse la création d'une nouvelle et renvoie "table existante"
  129.         printf("table existante\n");
  130.         return;
  131.     }
  132.     scanf("%s", choix);                             //demande nom table
  133.     strcpy(t->nom, choix);                          //copie le nom de la table insérée
  134.     scanf("%s", choix);                             //demande le nombre de table
  135.     t->nbChamps = atoi(choix);                      //copie le nombre de champ de la table insérée
  136.     for (int i = 0; i < t->nbChamps; ++i) {         //boucle pour enregistré chaque champ inséré ainsi que leur type
  137.         scanf("%s", choix);
  138.         strcpy(t->schema[i].nom, choix);
  139.         scanf("%s", choix);
  140.         strcpy(t->schema[i].type, choix);
  141.     }
  142. } //Création d'une table enregistrant les données, si une table est déjà présente la création d'une nouvelle sera refusée
  143.  
  144. void Afficher_shema(Table* t) {
  145.     char choix[lgMot + 1];
  146.     scanf("%s", choix);
  147.     if (strcmp(t->nom, choix) != 0) {
  148.         printf("table inconnue\n");
  149.         return;
  150.     }
  151.     printf("%s %hhu\n", t->nom, t->nbChamps);
  152.     for (int i = 0; i < t->nbChamps; ++i) {
  153.         printf("%s ", t->schema[i].nom);
  154.         printf("%s \n", t->schema[i].type);
  155.     }
  156. } //Affichage de la table demandée, si la table demandée n'existe pas affichage de "table inconnue"
  157.  
  158. void Insert_enregistrement(Table* t) {
  159.     char choix[lgMot + 1];
  160.     scanf("%s", &choix);
  161.     if (strcmp(choix, t->nom) != 0) {
  162.         printf("table inconnue");
  163.     }
  164.     else {
  165.         t->nombreEnregistrement = t->nombreEnregistrement + 1;
  166.         for (int i = 0; i < t->nbChamps; ++i) {
  167.             scanf("%s", t->Enregistrement[t->nombreEnregistrement].numData[i].nomData);
  168.         }
  169.     }
  170.  
  171. }
  172.  
  173. void Afficher_enregistrements(Table* t) {
  174.     char choix[lgMot];
  175.     scanf("%s", choix);
  176.     if (strcmp(choix, t->nom) == 0) {
  177.         for (int j = 1; j <= t->nombreEnregistrement; ++j) {
  178.             printf("%d ", j);
  179.             for (int i = 0; i < t->nbChamps; ++i) {
  180.                 printf("%s ", t->schema[i].type);
  181.                 printf("%s ", t->Enregistrement[j].numData[i].nomData);
  182.             }
  183.             printf("\n");
  184.         }
  185.     }
  186. }
  187.  
  188. void Afficher_enregistrement(Table* t) {
  189.     char choix[lgMot];
  190.     scanf("%s", choix);
  191.     if (strcmp(choix, t->nom) == 0) {
  192.         scanf("%s", choix);
  193.         printf("%d ", atoi(choix));
  194.         for (int i = 0; i < t->nbChamps; ++i) {
  195.             printf("%s ", t->schema[i].type);
  196.             printf("%s ", t->Enregistrement[atoi(choix)].numData[i].nomData);
  197.         }
  198.         printf("\n");
  199.     }
  200. }
  201.  
  202. void Delete_enregistrement(Table* t) {
  203.     char choix[lgMot];
  204.     scanf("%s", choix);
  205.     if (strcmp(choix, t->nom) != 0) {
  206.         return;
  207.     }
  208.     scanf("%s", choix);
  209.     for (int j = atoi(choix); j <= t->nombreEnregistrement; ++j) {
  210.         for (int i = 0; i < t->nbChamps; ++i) {
  211.             strcpy(t->Enregistrement[j].numData[i].nomData, t->Enregistrement[j + 1].numData[i].nomData);
  212.         }
  213.     }
  214.     t->nombreEnregistrement = t->nombreEnregistrement - 1;
  215. }
  216.  
  217. void Delete_table(Table* t) {
  218.     char choix[lgMot];
  219.     scanf("%s", choix);
  220.     if (strcmp(choix, t->nom) != 0) {
  221.         printf("Table inconnue");
  222.         return;
  223.     }
  224.     strcpy(t->nom, "");
  225.     t->nombreEnregistrement = 0;
  226.     t->nbChamps = 0;
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement