Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define max_champs 25
- #define lgMot 30
- #define lgMax 80
- #define max_data 20
- #define max_enr 100
- #pragma warning (disable:4996)
- /*Définition des structures de données :*/
- typedef struct {
- char nom[lgMot + 1];
- char type[lgMot + 1];
- } Champ; //Déclaration d'un nouveau type de variable structurée qui correspond au champ utilisé dans la table
- typedef struct {
- char nomData[lgMot + 1];
- } Data; //Déclaration d'un nouveau type de variable structurée qui correspond aux données ajoutées
- typedef struct {
- Data numData[max_data];
- } Enregistrement;
- typedef struct {
- char nom[lgMot + 1];
- Champ schema[max_champs];
- unsigned char nbChamps;
- Enregistrement Enregistrement[max_enr];
- unsigned char nombreEnregistrement;
- } Table; //Déclaration d'un nouveau type de variable structurée qui correspond à la table
- void Afficher_enregistrements(Table* t);
- void Create_table(Table* t);
- void Afficher_shema(Table* t);
- void Insert_enregistrement(Table* t);
- void Delete_enregistrement(Table* t);
- void Afficher_enregistrement(Table* t);
- void Delete_table(Table* t);
- void Select_enregistrement(Table* t);
- void compare_enregistrement(Table* t,int i);
- /*Programme principal*/
- int main() {
- Champ c;
- Table t;
- t.nombreEnregistrement = 0;
- char choix[lgMot];
- strcpy(t.nom, "");//char nom_table[lgMot] = "";
- while (1) {
- scanf("%s", choix);//choix utilisateur
- if (strcmp(choix, "Create_table") == 0) {
- Create_table(&t);
- }
- if (strcmp(choix, "Afficher_schema") == 0) {
- Afficher_shema(&t);
- }
- if (strcmp(choix, "Insert_enregistrement") == 0) {
- Insert_enregistrement(&t);
- }
- if (strcmp(choix, "Afficher_enregistrements") == 0) {
- Afficher_enregistrements(&t);
- }
- if (strcmp(choix, "Delete_enregistrement") == 0) {
- Delete_enregistrement(&t);
- }
- if (strcmp(choix, "Afficher_enregistrement") == 0) {
- Afficher_enregistrement(&t);
- }
- if (strcmp(choix, "Delete_table") == 0) {
- Delete_table(&t);
- }
- if (strcmp(choix, "Select_enregistrement") == 0) {
- Select_enregistrement(&t);
- }
- if (strcmp(choix, "Exit") == 0) {
- exit(0);
- }
- }
- system("pause"); return 0;
- }
- /*Déclaration des différentes fonctions :*/
- void compare_enregistrement(Table* t,int i) {
- char choix1[lgMot + 1], choix2[lgMot + 1]; //introduction d'une variable texte dans la fonction create table
- scanf("%s", &choix1);
- scanf("%s", &choix2);
- if (strcmp(t->schema[i].nom, "TEXT")==0) {
- }
- if (strcmp(t->schema[i].nom, "INT") == 0) {
- }
- if (strcmp(t->schema[i].nom, "FLOAT") == 0) {
- }
- if (strcmp(t->schema[i].nom, "DATE") == 0) {
- }
- }
- void Select_enregistrement(Table* t){
- char choix[lgMot + 1]; //introduction d'une variable texte dans la fonction create table
- scanf("%s", &choix);
- if (strcmp(choix, t->nom) != 0) {
- printf("table inconnue");
- return;
- }
- scanf("%s", choix);
- for (int i = 0; t->nbChamps; ++i) {
- if (strcmp(t->schema[i].nom, choix)==0) {
- compare_enregistrement(&t,i);
- }
- }
- }
- void compare_enregistrement(Table* t) {
- }
- void Create_table(Table* t) {
- char choix[lgMot + 1]; //introduction d'une variable texte dans la fonction create table
- 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"
- printf("table existante\n");
- return;
- }
- scanf("%s", choix); //demande nom table
- strcpy(t->nom, choix); //copie le nom de la table insérée
- scanf("%s", choix); //demande le nombre de table
- t->nbChamps = atoi(choix); //copie le nombre de champ de la table insérée
- for (int i = 0; i < t->nbChamps; ++i) { //boucle pour enregistré chaque champ inséré ainsi que leur type
- scanf("%s", choix);
- strcpy(t->schema[i].nom, choix);
- scanf("%s", choix);
- strcpy(t->schema[i].type, choix);
- }
- } //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
- void Afficher_shema(Table* t) {
- char choix[lgMot + 1];
- scanf("%s", choix);
- if (strcmp(t->nom, choix) != 0) {
- printf("table inconnue\n");
- return;
- }
- printf("%s %hhu\n", t->nom, t->nbChamps);
- for (int i = 0; i < t->nbChamps; ++i) {
- printf("%s ", t->schema[i].nom);
- printf("%s \n", t->schema[i].type);
- }
- } //Affichage de la table demandée, si la table demandée n'existe pas affichage de "table inconnue"
- void Insert_enregistrement(Table* t) {
- char choix[lgMot + 1];
- scanf("%s", &choix);
- if (strcmp(choix, t->nom) != 0) {
- printf("table inconnue");
- }
- else {
- t->nombreEnregistrement = t->nombreEnregistrement + 1;
- for (int i = 0; i < t->nbChamps; ++i) {
- scanf("%s", t->Enregistrement[t->nombreEnregistrement].numData[i].nomData);
- }
- }
- }
- void Afficher_enregistrements(Table* t) {
- char choix[lgMot];
- scanf("%s", choix);
- if (strcmp(choix, t->nom) == 0) {
- for (int j = 1; j <= t->nombreEnregistrement; ++j) {
- printf("%d ", j);
- for (int i = 0; i < t->nbChamps; ++i) {
- printf("%s ", t->schema[i].type);
- printf("%s ", t->Enregistrement[j].numData[i].nomData);
- }
- printf("\n");
- }
- }
- }
- void Afficher_enregistrement(Table* t) {
- char choix[lgMot];
- scanf("%s", choix);
- if (strcmp(choix, t->nom) == 0) {
- scanf("%s", choix);
- printf("%d ", atoi(choix));
- for (int i = 0; i < t->nbChamps; ++i) {
- printf("%s ", t->schema[i].type);
- printf("%s ", t->Enregistrement[atoi(choix)].numData[i].nomData);
- }
- printf("\n");
- }
- }
- void Delete_enregistrement(Table* t) {
- char choix[lgMot];
- scanf("%s", choix);
- if (strcmp(choix, t->nom) != 0) {
- return;
- }
- scanf("%s", choix);
- for (int j = atoi(choix); j <= t->nombreEnregistrement; ++j) {
- for (int i = 0; i < t->nbChamps; ++i) {
- strcpy(t->Enregistrement[j].numData[i].nomData, t->Enregistrement[j + 1].numData[i].nomData);
- }
- }
- t->nombreEnregistrement = t->nombreEnregistrement - 1;
- }
- void Delete_table(Table* t) {
- char choix[lgMot];
- scanf("%s", choix);
- if (strcmp(choix, t->nom) != 0) {
- printf("Table inconnue");
- return;
- }
- strcpy(t->nom, "");
- t->nombreEnregistrement = 0;
- t->nbChamps = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement