Example #1
0
int main(int argc, char *argv[]) {
    const int no_employees = 10;
    Database people;
    init_database (people, no_employees);
    print_database(people, no_employees);
    sort((int**)people, no_employees, comp_employee, swap_employee);
    print_database(people, no_employees);
    return 0;
}
Example #2
0
File: q9.c Project: eokeeffe/C-code
int menu()
{
	int user_choice;
	
	printf("1.Print Database\r\n");
	printf("2.Add part to database\r\n");
	printf("3.Remove part from database\r\n");
	printf("4.Search Database\r\n");
	printf("5.Exit Database\r\n");
	
	while( scanf("%d%*c",&user_choice) != 1)
	{
		fflush(stdin);
	}
	
	if(user_choice == 1){ print_database(); }
	if(user_choice == 2){ add_parts_to_database();}
	if(user_choice == 3){ remove_parts_from_database();}
	if(user_choice == 4){ search_database();}
	if(user_choice == 5){ exit_program();}
	else
	{
		printf("Please enter a proper value\r\n");
		menu();
	}
	
	return 0;
}
Example #3
0
File: q7.c Project: eokeeffe/C-code
int menu()
{
    int user_choice;

    printf("1.Print Database\r\n");
    printf("2.Search Database\r\n");
    printf("3.Exit Database\r\n");

    while( scanf("%d",&user_choice) != 1)
    {
        fflush(stdin);
    }

    if(user_choice == 1) {
        print_database();
    }
    if(user_choice == 2) {
        search_database();
    }
    if(user_choice == 3) {
        exit_program();
    }
    else
    {
        printf("Please enter a proper value\r\n");
        menu();
    }

    return 0;
}
Example #4
0
int main(/*int argc, char *argv[]*/)
{
  printf("coucou");
  FILE *file;
  file = fopen("Database.txt", "r");
  printf("Crash before init");
  database *data = init_database();
  printf("Crash before read");
  int nb_elt = read_data(file, data);
  printf("Crash before print");
  print_database(data, nb_elt);
  //write_file(data, file);
  fclose(file);
  free(data);
  return 0;
}
int
main(int argc, char **argv)
{
    unsigned opt;
    char *param, *filename=0, *endptr=0;
    unsigned short dbname=0xffff;
    int full=0;

    ham_u16_t names[1024];
    ham_size_t i, names_count=1024;
    ham_status_t st;
    ham_env_t *env;
    ham_db_t *db;

    ham_u32_t maj, min, rev;
    const char *licensee, *product;
    ham_get_license(&licensee, &product);
    ham_get_version(&maj, &min, &rev);

    getopts_init(argc, argv, "ham_info");

    while ((opt=getopts(&opts[0], &param))) {
        switch (opt) {
            case ARG_DBNAME:
                if (!param) {
                    printf("Parameter `dbname' is missing.\n");
                    return (-1);
                }
                dbname=(short)strtoul(param, &endptr, 0);
                if (endptr && *endptr) {
                    printf("Invalid parameter `dbname'; numerical value "
                           "expected.\n");
                    return (-1);
                }
                break;
            case ARG_FULL:
                full=1;
                break;
            case GETOPTS_PARAMETER:
                if (filename) {
                    printf("Multiple files specified. Please specify "
                           "only one filename.\n");
                    return (-1);
                }
                filename=param;
                break;
            case ARG_HELP:
                printf("hamsterdb %d.%d.%d - Copyright (C) 2005-2007 "
                       "Christoph Rupp ([email protected]).\n\n",
                       maj, min, rev);

                if (licensee[0]=='\0')
                    printf(
                       "This program is free software; you can redistribute "
                       "it and/or modify it\nunder the terms of the GNU "
                       "General Public License as published by the Free\n"
                       "Software Foundation; either version 2 of the License,\n"
                       "or (at your option) any later version.\n\n"
                       "See file COPYING.GPL2 and COPYING.GPL3 for License "
                       "information.\n\n");
                else
                    printf("Commercial version; licensed for %s (%s)\n\n",
                            licensee, product);

                printf("usage: ham_info [-db DBNAME] [-f] file\n");
                printf("usage: ham_info -h\n");
                printf("       -h:         this help screen (alias: --help)\n");
                printf("       -db DBNAME: only print info about "
                        "this database (alias: --dbname=<arg>)\n");
                printf("       -f:         print full information "
                        "(alias: --full)\n");
                return (0);
            default:
                printf("Invalid or unknown parameter `%s'. "
                       "Enter `ham_info --help' for usage.", param);
                return (-1);
        }
    }

    if (!filename) {
        printf("Filename is missing. Enter `ham_info --help' for usage.\n");
        return (-1);
    }

    /*
     * open the environment
     */
    st=ham_env_new(&env);
    if (st!=HAM_SUCCESS)
        error("ham_env_new", st);
    st=ham_env_open(env, filename, HAM_READ_ONLY);
    if (st==HAM_FILE_NOT_FOUND) {
        printf("File `%s' not found or unable to open it\n", filename);
        return (-1);
    }
    else if (st!=HAM_SUCCESS)
        error("ham_env_open", st);

    /*
     * print information about the environment
     */
    print_environment(env);

    /*
     * get a list of all databases
     */
    st=ham_env_get_database_names(env, names, &names_count);
    if (st!=HAM_SUCCESS)
        error("ham_env_get_database_names", st);

    /*
     * did the user specify a database name? if yes, show only this database
     */
    if (dbname!=0xffff) {
        st=ham_new(&db);
        if (st)
            error("ham_new", st);
    
        st=ham_env_open_db(env, db, dbname, 0, 0);
        if (st==HAM_DATABASE_NOT_FOUND) {
            printf("Database %u (0x%x) not found\n", dbname, dbname);
            return (-1);
        }
        else if (st)
            error("ham_env_open_db", st);
    
        print_database(db, dbname, full);
    
        st=ham_close(db, 0);
        if (st)
            error("ham_close", st);
        ham_delete(db);
    }
    else {
        /*
         * otherwise: for each database: print information about the database
         */
        for (i=0; i<names_count; i++) {
            st=ham_new(&db);
            if (st)
                error("ham_new", st);
    
            st=ham_env_open_db(env, db, names[i], 0, 0);
            if (st)
                error("ham_env_open_db", st);
    
            print_database(db, names[i], full);
    
            st=ham_close(db, 0);
            if (st)
                error("ham_close", st);
            ham_delete(db);
        }
    } 
    /*
     * clean up
     */
    st=ham_env_close(env, 0);
    if (st!=HAM_SUCCESS)
        error("ham_env_close", st);

    ham_env_delete(env);

    return (0);
}
main()
{
	/*Declarations*/
	tree tr;
	status_code SC=SUCCESS;
	int ht,num,option,contnue,num_lo=0,num_hi=0;
	char dumbo[2];
	int number;
	char name[NAME_LEN];
	char dsgn[DSGN_LEN];
	char add[ADD_LEN];
	long int phone;
	initialize(&tr);
	/*Declarations End*/
	do
	{
		/* Asking for different operations */
		puts("ENTER the option as per the operation you want to do. ENTER :-\n");
		puts("1- insert/update\n2- delete\n3- Search\n4- getNumRecords\n5- Height\n6- Range Search\n7- Print Database\n\n");
		printf("Your Choice is:- ");
		scanf("%d",&option);
		printf("\n\n");
		switch (option)
		{
			/* INSERT/UPDATE */
			case 1: {
						    printf("***********INSERT**********\n\n");
						    /* Data Entering Start */
						    printf("Enter Employee's Number :-\t");
							scanf("%d",&number);
							printf("Enter Employee Name :-\t");
							gets(dumbo);
							gets(name);
							remove_space_make_uppercase(name);
							printf("Enter Employee's Designation :-\t");
							gets(dsgn);
							remove_space_make_uppercase(dsgn);
							printf("Enter Employee's Address :-\t");
							gets(add);
							remove_space_make_uppercase(add);
							printf("Enter Employee's Phone Number :-\t");
							scanf("%lu",&phone);
							/* Data Entering End */
							/* Inserting/Updating Data */
							SC=insert_emp(&tr,number,name,dsgn,add,phone);
							if(SC==SUCCESS)
							{
								puts("\n**********Data inserted**********\n");	
							}
							else
							{
								puts("\n**********Data insertion failed**********\n");	
							}
					  		break;
				     }
			/*Search*/
			case 3:  {
							printf("Enter Employee's Number :-\t");
							scanf("%d",&number);
							search(&tr,number);
							break;
					 }
			/* Get Num Records */
			case 4:  {
							num=get_num_records(&tr);
							printf("Number of records present in the tree is %d",num);
							break;
			         }
			/* Height of the tree */
			case 5:  {
							ht=height(&tr);
							printf("Height of the tree is %d",ht);
							break;
			         }
			/* Range Search */
			case 6:  {
							printf("\nEnter lower bound :- \t");
							scanf("%d",&num_lo);
							printf("\nEnter upper bound :- \t");
							scanf("%d",&num_hi);
							if(num_lo<num_hi)
							{
								range_search(&tr,num_lo,num_hi);
							}
							else
							{
								printf("Please enter valid bounds.\n");	
							}
							break;
					 }
			/* Print Database */
			case 7:  {
							print_database(&tr);
							break;
					 }
			/* Default */
			default: {
							break;
					 }
		}
		/* Asking for CHOICE to Continue */
		puts("\n\nIf you want to continue... ? Enter 1 if YES or 0 if NO\n");
		printf("Your Choice is:- ");
		scanf("%d",&contnue);
		printf("\n\n");
	}while(contnue==1);
	getch();
}