Task 5 is changed
This commit is contained in:
parent
e5b2c01295
commit
36497ec462
50 changed files with 1007904 additions and 144 deletions
|
@ -27,10 +27,21 @@ void delete_list (node * head)
|
|||
}
|
||||
}
|
||||
|
||||
void delete_nodes (node *head, const int count)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
node *temp = head;
|
||||
head = head->next;
|
||||
|
||||
delete_node(temp);
|
||||
}
|
||||
}
|
||||
|
||||
io_status read_list (node **list, const char *filename)
|
||||
{
|
||||
FILE *fp = 0;
|
||||
char *string, buf[LEN_STR];
|
||||
char *string, buf[LEN_STR] = {0};
|
||||
node *head, *lunit, *unit;
|
||||
|
||||
head = lunit = unit = NULL;
|
||||
|
@ -40,6 +51,7 @@ io_status read_list (node **list, const char *filename)
|
|||
|
||||
while (fgets(buf, LEN_STR, fp))
|
||||
{
|
||||
int len = strcspn(buf, "\n");
|
||||
unit = (node *)malloc(sizeof(node));
|
||||
if (!unit) {
|
||||
fclose(fp);
|
||||
|
@ -50,8 +62,8 @@ io_status read_list (node **list, const char *filename)
|
|||
|
||||
unit->next = NULL;
|
||||
|
||||
buf[strcspn(buf, "\n")] = '\0';
|
||||
string = strdup(buf);
|
||||
buf[len] = '\0';
|
||||
string = (char *)malloc((len+1) * sizeof(char));
|
||||
if (!string) {
|
||||
fclose(fp);
|
||||
free(unit);
|
||||
|
@ -60,6 +72,8 @@ io_status read_list (node **list, const char *filename)
|
|||
return ERR_MEM;
|
||||
}
|
||||
|
||||
strcpy(string, buf);
|
||||
|
||||
unit->string = string;
|
||||
if (!lunit)
|
||||
head = unit;
|
||||
|
|
|
@ -4,8 +4,17 @@
|
|||
#include "node.h"
|
||||
#include "status.h"
|
||||
|
||||
int get_length (node * head);
|
||||
void delete_list (node * head);
|
||||
#include <stdlib.h>
|
||||
|
||||
static inline void delete_node (node *head)
|
||||
{
|
||||
free(head->string);
|
||||
free(head);
|
||||
}
|
||||
|
||||
int get_length (node *head);
|
||||
void delete_nodes (node *head, const int count);
|
||||
void delete_list (node *head);
|
||||
io_status read_list (node **list, const char *filename);
|
||||
void print_list (node *head, const int p);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue