1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
struct INFO
{
char apa[MAX];
char gaz[MAX];
char curent[MAX];
long int diferenta;
};
// TIMP
struct TIMP
{
char zi[MAX];
char luna[MAX];
char an[MAX];
};
int diferentaIndex(char index1[MAX], char index2[MAX])
{
long int rezultat;
long int x, y;
x = atoi(index1);
y = atoi(index2);
rezultat = y - x;
return rezultat;
}
//------------------------------------------------//
// ** Adauga info apa ** //
void adaugaInfoApa(struct INFO* info, struct TIMP* timp)
{
BOOL found = FALSE;
FILE *file;
char fname[MAX] = "apa.c";
char temp[MAX];
file = fopen(fname, "a+");
system("cls");
printf("\n\t\t\t\tCENTRU INDEX\n\t\t\t\t------------");
printf("\n\n\n\tSectiunea Adauga Info apa\n\t-------------------------\n\n");
printf("\n\n Introduceti Metri cubi: ");
scanf("%30s", temp);
fseek(file, 0, SEEK_END);
long size = ftell(file);
do
{
rewind(file);
while(fscanf(file, "%15s", info->apa) == 1)
{
if(strcmp(temp, info->apa) == 0)
{
found = TRUE;
printf("\n\n Indexul introdus exista deja");
Sleep(1500);
system("cls");
fclose(file);
return;
}
}
if(!found)
{
//rewind(file);
printf("\n\n\n\tData\n\t----");
printf("\n\n Ziua: ");
scanf("%30s", timp->zi);
printf("\n\n Luna: ");
scanf("%30s", timp->luna);
printf("\n\n Anul: ");
scanf("%30s", timp->an);
if(size != 0)
{
char tmpApa[6] = {0};
for (int ln = 0; fscanf(file, "%5s | %d | %d | %d | %d", tmpApa, &ln, &ln, &ln, &ln) != EOF; );
info->diferenta = diferentaIndex(tmpApa, temp);
fprintf(file, "%s | %s | %s | %s | %ld \n", temp, timp->zi, timp->luna, timp->an, info->diferenta);
}
else
{
fprintf(file, "%s | %s | %s | %s | 0 \n", temp, timp->zi, timp->luna, timp->an);
}
fclose(file);
system("attrib +h +s apa.c");
printf("\n\n\n\tIndexul a fost salvat in baza de date");
Sleep(2000);
system("cls");
return;
}
}while(size != 0);
}
|