Added list pointer printing function
This commit is contained in:
parent
b22a0977aa
commit
560ac1e59f
@ -79,7 +79,7 @@ void show_read(Node** list)
|
|||||||
char path[101], line[256], * title, * author, * year;
|
char path[101], line[256], * title, * author, * year;
|
||||||
FILE* CSV;
|
FILE* CSV;
|
||||||
|
|
||||||
printf("Enter the path to the file of haram: ");
|
printf("Enter the path of the CSV file to open: ");
|
||||||
gets_s(path, 101);
|
gets_s(path, 101);
|
||||||
|
|
||||||
if (!(CSV = fopen(path, "r")))
|
if (!(CSV = fopen(path, "r")))
|
||||||
@ -107,17 +107,17 @@ void show_read(Node** list)
|
|||||||
|
|
||||||
void show_write(Node** list)
|
void show_write(Node** list)
|
||||||
{
|
{
|
||||||
char path[101], line[256];
|
char path[101];
|
||||||
FILE* CSV;
|
FILE* CSV;
|
||||||
Node* node = *list;
|
Node* node = *list;
|
||||||
Book* book;
|
Book* book;
|
||||||
|
|
||||||
printf("Enter the path to the file_s: ");
|
printf("Enter the path of the file to write: ");
|
||||||
gets_s(path, 101);
|
gets_s(path, 101);
|
||||||
|
|
||||||
if (!(CSV = fopen(path, "w")))
|
if (!(CSV = fopen(path, "w")))
|
||||||
{
|
{
|
||||||
puts("Failed to read file!\n");
|
puts("Failed to write file!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +131,11 @@ void show_write(Node** list)
|
|||||||
fclose(CSV);
|
fclose(CSV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void show_print_pointers(Node** list)
|
||||||
|
{
|
||||||
|
list_print_pointers(*list);
|
||||||
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
Node* list = NULL;
|
Node* list = NULL;
|
||||||
@ -144,6 +149,7 @@ void main(void)
|
|||||||
{"Remove item by index", '6', (void*)&show_remove, &list},
|
{"Remove item by index", '6', (void*)&show_remove, &list},
|
||||||
{"READ", 'r', (void*)&show_read, &list},
|
{"READ", 'r', (void*)&show_read, &list},
|
||||||
{"RIDE", 'w', (void*)&show_write, &list},
|
{"RIDE", 'w', (void*)&show_write, &list},
|
||||||
|
{"Print pointers", 'p', (void*)show_print_pointers, &list},
|
||||||
{"BLANK", ' ', NULL, NULL},
|
{"BLANK", ' ', NULL, NULL},
|
||||||
{"Quit", 'q', (void*)&exit, NULL}
|
{"Quit", 'q', (void*)&exit, NULL}
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "linked_list.h"
|
#include "linked_list.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
static Node* create(void* data)
|
static Node* create(void* data)
|
||||||
{
|
{
|
||||||
@ -20,6 +21,16 @@ void list_print(Node* head, void (*print_func)(void*))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void list_print_pointers(Node* head)
|
||||||
|
{
|
||||||
|
printf("%-19s%-19s%-19s%-19s\n", "Prev", "Current", "Next", "Data");
|
||||||
|
while (head)
|
||||||
|
{
|
||||||
|
printf("0x%p 0x%p 0x%p 0x%p\n", head->prev, head, head->next, head->data);
|
||||||
|
head = head->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void list_push(Node** head, void* data)
|
void list_push(Node** head, void* data)
|
||||||
{
|
{
|
||||||
Node* node = create(data);
|
Node* node = create(data);
|
||||||
|
@ -7,6 +7,8 @@ typedef struct Node {
|
|||||||
|
|
||||||
void list_print(Node* head, void (*print_func)(void*));
|
void list_print(Node* head, void (*print_func)(void*));
|
||||||
|
|
||||||
|
void list_print_pointers(Node* head);
|
||||||
|
|
||||||
void list_push(Node** head, void* data);
|
void list_push(Node** head, void* data);
|
||||||
|
|
||||||
void list_append(Node** head, void* data);
|
void list_append(Node** head, void* data);
|
||||||
|
Reference in New Issue
Block a user