Exemplo n.º 1
0
/* Initialize the list */
List *init_list(){
    List* new_list = malloc(sizeof(List));
    Node *header = create_empty_node();
    new_list -> header = header;
    new_list -> length = 0;
    return new_list;
};
Exemplo n.º 2
0
void delete_current_line()
{
	node * temp = current_node -> next;
	node * temp_start_display_node = start_display_node -> next;
	delete_node();
	if(current_node == head && current_node == tail)
	{
		// while deleting the last line of a file we need to create a
		// empty node and assign the current_node and start_display_node as head.
		create_empty_node();
		current_node = start_display_node = head;
	}
	else if(current_node == head)
	{
		start_display_node = current_node = head;
	}
	else if(current_node == tail)
	{
		// start display line will not be changed..
		// because we are not touching this when we are deleting the last line.
		current_node = tail;
	}
	else
	{
		start_display_node = temp_start_display_node;
		current_node = temp;
	}
}
Exemplo n.º 3
0
struct bstNode * create_node(int value)
{
	struct bstNode * tmp = create_empty_node();
	if (!tmp){
		printf("\nERROR: cannot create another node for binary tree.");
		abort(); // come down crashing.
	}
	tmp->left = NULL;
	tmp->right = NULL;
	tmp->value = value;
	return tmp;
}
Exemplo n.º 4
0
/**
 * @brief The main entry point to pwl.
 *
 * The main job of main is to call stats read function. On execution of the program,
 * an absolute path is printed out. File is then read and closed, and stats are
 * printed to stdout. Errors are printed out if 1. the user does not supply 
 * the correct number of args, 2. if the file cannot be opened. 
 *
 * @param argc is only used to make sure the user entered correct number of args.
 * @param argv a path to a single file as a string needs to be added.
 * @return 0 if it was ok
 */
int main(int argc, const char * argv[])
{
    List* list;
    const char* infile;
    FILE* in;
    char* real_path;
    /* adding function header to clear compile time warning. */
    char *realpath(const char *path, char *resolved_path);
    
    if(argc != 2)
    {
        fprintf(stderr, "wrong number of args. ./program path-to-file.txt\n");
        return 1;
    }
    infile = argv[1];

    in = fopen(infile, "rb");
    
    if(in == NULL)
    {
        fprintf(stderr, "couldn't open %s for reading\n", infile);
        return 2;
    }
    
    real_path = realpath(infile, NULL);

    /* print the path of the file */
    printf("File %7s %s\n", ":", real_path);
    free(real_path);

    /* create a list */
    list = create_empty_node();
    
    /* call the stats read function */
    read(in, list);
    
    fclose(in);
    
    /* print to stdbout */
    print_stats(list);
    
    return 0;
}
Exemplo n.º 5
0
/* create node with node 's value */
Node *create_node(void *value){
    Node *node = create_empty_node();
    node -> value = value;
    return node;
};
Exemplo n.º 6
0
struct t_node *create_node(void *key) {
    struct t_node *temp = create_empty_node();
    temp->data = key;
    temp->left = temp->right = temp->parent = NULL;
    return temp;
}
Exemplo n.º 7
0
struct node *create_node(void *key){
	struct node *temp = create_empty_node();
	temp->data = key;
	temp->next = temp->prev = NULL;
	return temp;
}