#include #include #include #define N 5 struct Poleis { char kp[6]; char po[20]; int pl; char no[20]; }; struct IPoleis{ char kp[6]; int dief; }; main() { struct Poleis pol; struct IPoleis *bpol; FILE *f; FILE *k; char oa[20]="Poleis.dat"; char ob[20]="Poleis.ndx"; int pl, m=0, i, j, tm, sinexeia; f=fopen(oa, "rb"); if (!f) { f=fopen(oa, "wb"); k=fopen(ob, "wb"); fclose(k); pl=0; } else { k=fopen(ob, "rb"); fseek(k, 0, SEEK_END); pl=ftell(k) / sizeof(struct IPoleis); fclose(k); fseek(f, 0, SEEK_END); } m=pl; bpol = malloc( (pl+N) * sizeof(struct IPoleis)); printf("\neisagwgi eggrafwn\n\n"); do { printf("eisagwgi kp: "); scanf("%s", &pol.kp); printf("eisagwgi po: "); scanf("%s", &pol.po); printf("eisagwgi pl: "); scanf("%d", &pol.pl); printf("dwse to no: "); scanf("%s", &pol.no); fwrite(&pol, sizeof(struct Poleis), 1, f); strcpy(bpol[m].kp, pol.kp); bpol[m].dief = m; m++; printf("\nthelete nea eisagwgi? Eisagete 1 gia nai: "); scanf("%d", &sinexeia); if (sinexeia==1) if (m == pl+N) { k=fopen(oa, "rb+"); fseek(k, 0, SEEK_END); for (i=pl; i