All pastes #799488 Raw Edit

Someone

public c v1 · immutable
#799488 ·published 2007-11-27 18:04 UTC
rendered paste body
#include <stdio.h>#include <string.h>#include <stdlib.h>#define N 5struct 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<pl+N; i++) 					fwrite(&bpol[i], sizeof(struct IPoleis), 1, k);				fclose(k);				free(bpol);				pl+=N;				bpol = malloc( (pl+N) * sizeof(struct IPoleis));			}			} while ((sinexeia == 1) && (m < pl+N));			fclose(f);	k=fopen(ob, "rb+");	fseek(k, 0, SEEK_END);	for(i=pl;i<m;i++)		fwrite(&bpol[i], sizeof(struct IPoleis), 1, k);	fclose(k);}