Commit 587fa942 authored by William Sha's avatar William Sha
Browse files

Auto stash before merge of "master" and "origin/master"

parent 71cd68b2
......@@ -29,15 +29,7 @@ int main()
if (DEBUG) printf("Initialization of an instance of List...\n\n");
List* default_list;
initialize(&default_list);
if (default_list->head == NULL) printf("NULL\n");
/*printf("What do you want to add at the beginning ?");
scanf("%s", str_number);
insert_empty_list(default_list, str_number);
printf("%s\n", default_list->head->data);
scanf("%s", test);
insert_end_list(default_list, test);
printf("%c\n", default_list->tail->data[0]);*/
while(action != 8){
if (DEBUG) printf("Entering in a new menu prompt...\n\n");
......@@ -63,7 +55,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);
if (DEBUG) printf("Data inserted case : %s\n", default_list->head->data);
break;
case TOKEN_ADD_NB_END:
......
......@@ -17,31 +17,60 @@ void initialize(List** list){
(*list)->tail = NULL;
}
void insert_empty_list(List* list, char* str){
/* if (DEBUG) printf("INSERT_EMPTY_LIST\n");
if (list->head || list->tail){
void insert_empty_list(List** list, char* str){
if (DEBUG) printf("INSERT_EMPTY_LIST\n");
if(*list) printf("cool\n");
if ((*list)->head || (*list)->tail){
printf("List is not empty... use another insert function.\n");
return;
}
int l = length(str);
// Tant qu'il reste quelque chose dans le str
// Cr�er un �l�ment
// Ins�rer les 5 premi�res lettres du str
// Brancher l'�l�ment
// Fin tant que
// Cr�er un �l�ment vide
// Le brancher
int length = strlen(str), total = 0, i;
printf("str length : %d\n", length);
while (str < l){
while(length > 0){
if (DEBUG) printf("WHILE\n");
i = 0;
Element* e = malloc(sizeof(Element));
char* tmp=malloc(sizeof(char)*(N+1));
strncpy(tmp, str, N);
e->data = tmp;
e->data = malloc(sizeof(char)*N);
while(length > 0 && i < 5){ // tant qu'il reste de l'input et que l'on a pas rempli la data
*(e->data+i) = *(str+total+i);
i++;
length--;
}
total += i;
e->next = NULL;
(*list)->head = e;
(*list)->tail = e;
}
list->head = e;
list->tail = e;
if (DEBUG) printf("FLAG 2\n");
Element* e_vide = malloc(sizeof(Element));
e_vide->data = NULL;
e_vide->next = NULL;
(*list)->tail->next = e_vide;
if (DEBUG) printf("Data inserted : %s\n", list->head->data);
if (DEBUG) printf("FLAG 3\n");
str+=5;
}
*/
/*Element* e = malloc(sizeof(Element));
char tmp[N];
strncpy(tmp, str, N);
e->data = malloc(sizeof(char)*N);
e->data = tmp;
e->next = NULL;
list->head = e;
list->tail = e;*/
if (DEBUG) printf("Data inserted : %s\n", (*list)->head->data);
}
......@@ -50,7 +79,7 @@ void insert_beginning_list(List* list, char* str){
// empty list
if (list->head == NULL && list->tail == NULL){
if (DEBUG) printf("The list is empty...\n");
insert_empty_list(list, str);
insert_empty_list(&list, str);
return;
}
......
......@@ -20,7 +20,7 @@ typedef struct list{
} List;
void initialize(List** list);
void insert_empty_list(List* list, char* str);
void insert_empty_list(List** list, char* str);
void insert_beginning_list(List* list, char* str);
void insert_end_list(List* list, char* str);
int insert_after_position(List* list, char* str, int p);
......
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