#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Max 500
typedef struct
{
char Matricule[50];
char Model[30];
char Price[30];
int KilometrePerHour;
char Etat[50];
}
Voiture;
Voiture info[Max];
void stockinfo();
void Saveinfo();
void Displayinfo();
void displayAll();
int n;
void stockinfo()
{
int i;
printf("How many Cars You Want To Add ? \n");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter The Matricule : \n");
scanf("%s", info[i].Matricule);
printf("Enter The Module : \n");
scanf("%s", info[i].Model);
printf("Enter The Price : \n");
scanf("%s", info[i].Price);
printf("Enter The Kilometere Per Hour : \n");
scanf("%d", &info[i].KilometrePerHour);
printf("Enter The Case : \n");
scanf("%s", info[i].Etat);
}
}
void Saveinfo()
{
FILE * save;
save = fopen("CarsParc.doc", "a");
if (save == NULL)
{
printf("The file is Not Created Succefully..\n");
}
else
{
int i;
for (i = 0; i < n; i++)
{
fprintf(save, "\t\tThe Information Of %s Car..\n", info[i].Model);
fprintf(save, "The Matricule :%s\n", info[i].Matricule);
fprintf(save, "The Model :%s\n", info[i].Model);
fprintf(save, "The Price :%s\n", info[i].Price);
fprintf(save, "The Kilometre/h :%d\n", info[i].KilometrePerHour);
fprintf(save, "Tha Case (New/Used) :%s\n", info[i].Etat);
fprintf(save, "\n\n");
}
}
fclose(save);
}
/*i meant this function*/
void Displayinfo()
{
FILE * save;
save = fopen("CarsParc.doc", "r");
if (save == NULL)
{
printf("The file is Not Created Succefully..\n");
}
else
{
char T[100];
char mtrcl[100];
do { fgets(T, 100, save);
printf("Enter The Matricule : \n");
scanf("%s", mtrcl);
int i;
if (strcmp(T, mtrcl) == 0)
{
for (i = 1; i <= 7; i++)
{
fgets(T, 100, save);
printf("%s", T);
}
}
} while (strcmp(T, mtrcl) != 0);
fclose(save);
}
}
void displayAll()
{
FILE * save;
save = fopen("CarsParc.doc", "r");
if (save == NULL)
{
printf("The file is Not Created Succefully..\n");
}
else
{
char copy;
do { copy = fgetc(save);
printf("%c", copy);
} while (copy != EOF);
fclose(save);
}
}
main()
{
/*code */
int choice;
printf("\t\t Welcome To Cars Parc : \n");
printf("1-Add Car : |Click One.. | \n");
printf("2-Search for Specific Car : |Click Two.. |\n");
printf("3-See All The informations : |Click Three..|\n");
scanf("%d", &choice);
system("cls");
do {
if (choice == 1)
{
stockinfo();
Saveinfo();
system("cls");
int back;
printf("The Informations Of This %s Car in Saved Now..\n", info[Max].Model);
printf("To Back To The Menue Click 0 ..\n");
scanf("%d", &back);
if (back == 0)
{
system("cls");
main();
}
else
{
printf("This is The End Of The Programme..");
}
}
if (choice == 2)
{
Displayinfo();
int back;
printf("\n\n\n");
printf("To Back To The Menue Click 0 ..\n");
scanf("%d", &back);
if (back == 0)
{
system("cls");
main();
}
else
{
printf("This is The End Of The Programme..");
}
}
if (choice == 3)
{
displayAll();
int back;
printf("\n\n\n");
printf("To Back To The Menue Click 0 ..\n");
scanf("%d", &back);
if (back == 0)
{
system("cls");
main();
}
else
{
printf("This is The End Of The Programme..");
}
}
} while (choice != 3);
}