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;
}
Beispiel #2
0
int main( int argc, char* argv[] ){

	int i,x;
	int fdhp1;
	
	srand( time(NULL) );
	
	BF_Init();

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////	
	if ( (fdhp1 = HP_OpenFile("hp1")) < 0 )   
    {
		BF_PrintError("Error opening file hp1");
		return -1;
	}
	x=15;
	printf("\nSearching for records with id 15 in file hp1\n");
	HP_GetAllEntries(fdhp1, "id", &x);
	
	printf("\nSearching for records with name VASSILIS in file hp1\n");
	HP_GetAllEntries(fdhp1, "name", "VASSILIS");
	
	printf("\nDeleting records with name VASSILIS in file hp1\n");
	if ( HP_DeleteEntry (fdhp1, "name", "VASSILIS") < 0)
	{
         BF_PrintError("Error deleting record in file hp1");
         HP_CloseFile(fdhp1);
         return -1;
    }

    printf("\nSearching for records with name VASSILIS in file hp1\n");
	HP_GetAllEntries(fdhp1, "name", "VASSILIS");          /* No entries found */
	
	i = 0;
	while ( i < 15 )                        /* Insert 15 records in heap file */
    {
		Record r = randomRecord();
		if( HP_InsertEntry (fdhp1, r) < 0)
        {
            BF_PrintError("Error inserting record in file hp1");
		    HP_CloseFile(fdhp1);
		    return -1;
        }
        printf("\nRecord (%d, %s, %s, %s) was successfully inserted in file hp1\n", r.id, r.name, r.surname, r.city);
		i++;
	}
                                  /* Print everything that exists in file hp1 */
	printf("Printing everything in file hp1\n");
	HP_GetAllEntries(fdhp1, NULL, NULL);
	x=12;
	printf("\nDeleting records with id 12 in file hp1\n");
	if ( HP_DeleteEntry (fdhp1, "id", &x) < 0)
	{
         BF_PrintError("Error deleting record in file hp1");
         HP_CloseFile(fdhp1);
         return -1;
    }
	
	printf("\nSearching for records with surname PAPAPETROU in file hp1\n");
	HP_GetAllEntries(fdhp1, "surname", "PAPAPETROU");
	
	if( HP_CloseFile(fdhp1) < 0)
	{
        BF_PrintError("Error closing file hp1");
        return -1;
    }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////    
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
	return 0;
}