コード例 #1
0
int main(int argc, char** argv) 
{
	int heapFile, i = 25;	/*to i dinetai san orisma gia tin get otan psaxnoume gia int*/
	char ch = 'M';			/*to ch dinetai san orisma stinget otan psaxnoume gia char*/
	Record record;

	/* Create heap file */
	if(HP_CreateFile(FILENAME_HEAP) < 0) 
	{
		fprintf(stderr, "Error creating heap file.\n");
		exit(EXIT_FAILURE);
	}
	
	/* Open heap file */
	if ((heapFile = HP_OpenFile(FILENAME_HEAP)) < 0) 
	{ 
		fprintf(stderr, "Error opening heap file.\n");
		exit(EXIT_FAILURE);
	}

	while (!feof(stdin)) 
	{ /* read line, until eof */

		scanf("%d %s %s %c %s %d %c %d %d", &record.id, record.name, record.surname, record.status, record.dateOfBirth, &record.salary, record.section, &record.daysOff, &record.prevYears);
				
		/* Insert record in heap file */
		if (HP_InsertEntry(heapFile, record) < 0) 
		{ 
			fprintf(stderr, "Error inserting entry in heap file.\n");
			HP_CloseFile(heapFile);
			exit(EXIT_FAILURE);
		}
	}
	/*--------------------GETALLENTRIES------------------------*/
	//HP_GetAllEntries(heapFile, "id", &i);//
	//HP_GetAllEntries(heapFile, "name", "Emmanouil");//
	//HP_GetAllEntries(heapFile, "status", &ch);//
	HP_GetAllEntries(heapFile, NULL, NULL);
	
	/* Close heap file */
	if (HP_CloseFile(heapFile) < 0) 
	{ 
		fprintf(stderr, "Error closing heap file.\n");
		exit(EXIT_FAILURE);
	}

	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: testforhp.c プロジェクト: saksoo/DatabaseSystem
int main() {
	int x,fd,i;
	Record temp;
	BF_Init();
	x = HP_CreateFile("arxeio");	
	fd = HP_OpenFile("arxeio");
	strcpy(temp.name,"nikos");
	strcpy(temp.surname,"liappas");
	strcpy(temp.city,"athens");
	for(i=0;i<100;i++) {
		temp.id=i;
		x=HP_InsertEntry(fd,temp);
	}
	x=97;
	x=HP_DeleteEntry(fd,"surname","liappas");
	HP_GetAllEntries(fd,"id",NULL);
	return 0;
}