Commit 39364853 authored by William Sha's avatar William Sha
Browse files

Resolved empty_list_insert function

parent cc53bc28
No preview for this file type
......@@ -51,6 +51,7 @@ int main()
printf("What do you want to add at the beginning ? ");
scanf("%s", str_number);
insert_beginning_list(default_list, str_number);
if (DEBUG) printf("Data inserted : %s\n", default_list->head->data);
break;
case TOKEN_ADD_NB_END:
......@@ -72,7 +73,7 @@ int main()
break;
case TOKEN_DSP_LI_STD:
display(NULL);
display(default_list);
break;
case TOKEN_RMX_LI_ALL:
......
No preview for this file type
No preview for this file type
......@@ -11,14 +11,15 @@
<stdlib.h>
"tp3.h"
1510225412 source:c:\users\william\projets c\ai01_tp1\tp3.c
1510745573 source:c:\users\william\projets c\ai01_tp1\tp3.c
<stdio.h>
<stdlib.h>
<string.h>
"tp3.h"
1510225984 c:\users\william\projets c\ai01_tp1\tp3.h
1510745564 c:\users\william\projets c\ai01_tp1\tp3.h
1510225974 source:c:\users\william\projets c\ai01_tp1\main.c
1510744164 source:c:\users\william\projets c\ai01_tp1\main.c
<stdio.h>
<stdlib.h>
"tp3.h"
......
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0">
<File name="main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1664" topLine="44" />
<Cursor1 position="1294" topLine="30" />
</Cursor>
</File>
<File name="tp3.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="tp3.c" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="327" topLine="21" />
<Cursor1 position="982" topLine="21" />
</Cursor>
</File>
<File name="tp3.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="337" topLine="11" />
<Cursor1 position="469" topLine="8" />
</Cursor>
</File>
</CodeBlocks_layout_file>
......@@ -25,15 +25,24 @@ void insert_empty_list(List* list, char* str){
return;
}
Element* e = malloc(sizeof(Element));
char tmp[N];
strncpy(tmp, str, N);
e->data = tmp;
e->next = NULL;
list->head = e;
list->tail = e;
int l = length(str);
while (str < l){
Element* e = malloc(sizeof(Element));
char* tmp=malloc(sizeof(char)*(N+1));
strncpy(tmp, str, N);
e->data = tmp;
e->next = NULL;
list->head = e;
list->tail = e;
if (DEBUG) printf("Data inserted : %s\n", list->head->data);
str+=5;
}
if (DEBUG) printf("Data inserted : %s\n", list->head->data);
}
void insert_beginning_list(List* list, char* str){
......@@ -47,13 +56,15 @@ void insert_beginning_list(List* list, char* str){
Element* e = malloc(sizeof(Element));
if (DEBUG) printf("Trying to put input into a new element...\n");
char tmp[N];
if (DEBUG) printf("Copy of string...\n");
strncpy(tmp, str, N);
e->data = tmp;
// changes the chain to plug the new element
if (DEBUG) printf("Reorganizing the list...%p, %s\n", list, str);
if (DEBUG) printf("Reorganizing the list...\n");
e->next = list->head;
list->head = e;
}
......@@ -89,6 +100,13 @@ int sort(List* list){
void display(List* list){
if (DEBUG) printf("DISPLAY\n");
if(!list || !list->head){
printf("Nothing to display...\n");
return;
}
printf("DATA : %c", list->head->data[0]);
}
void destruct(List* list){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment