Ejemplo n.º 1
0
int d_read_from_file(const char * filename) {
 	
	// modified from http://www.programmingsimplified.com/c-program-read-file

	char ch;
	char wordbuff[MAX_WORD_SIZE];
	char meanbuff[MAX_DESC_SIZE];
	int control = 0;
   	FILE *fp;
	struct entry input;
 
  	fp = fopen(filename,"r"); // read mode
 
  	if( fp == NULL ) {
  	    perror("Error while opening the file.\n");
      	return 0;
   	}
 
  	printf("The contents of %s file are :\n", filename);
 
   	while( ( ch = fgetc(fp) ) != EOF ) {
      	printf("%c",ch);
	    if (ch == ' ' && control == 0) {
			strcpy(input.word, wordbuff);
			strcpy(wordbuff, "");
			inc(&control);
	    }
	    else if (ch == '\n') {
			strcpy(input.meaning, meanbuff);
			d_insert(&input);
			strcpy(meanbuff, "");
			inc(&control);
	    }
	    else if (ch != '.') {
			if (control = 0) {
	   			append(wordbuff, ch);
			}
			
			else if (control = 1) {
	    		append(meanbuff, ch);
			}
	    }
	}
   	fclose(fp);
   	return 1;
	
}
Ejemplo n.º 2
0
int main()
{

    bptree_node* root = NULL;
    int i, search_test,insert_test;
    search_test  = 1 << 10;
    insert_test = 1 << 10;
    for (i = 1;i <= insert_test;++i) {
        root = d_insert(root,i,i);
        //d_search(root,i-1);
    }
    for (i = 1;i <= insert_test / 3; ++i) {
        delete_bptree_node(root,i);
    }
    for (i = 1;i <= search_test;++i) {
        d_search(root,i);
    }
    puts("");
    return 0;
}