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

Default behavior for functions, pending for implementation


Set initial loop for user menu

Implementation of the functions is still pending...
parent f70780bd
No preview for this file type
......@@ -4,6 +4,68 @@
int main()
{
printf("Hello world!\n");
if (DEBUG) printf("Initialization of ChainedLists...\n\n");
int action; // represents the choice of the user
printf("*****CHAINED LISTS*****\n");
printf("**UTC - November 2017**\n");
printf("*****W.Sha - Y.Ly******\n\n");
if (DEBUG) printf("Initialization of an instance of List...\n\n");
while(action != 8){
if (DEBUG) printf("Entering in a new menu prompt...\n\n");
action = 0;
// action prompt
display_menu();
printf("Your choice : ");
fflush(stdin);
scanf("%d", &action);
while(action == 0 || action < 1 || action > 8){ // not a number or number not in interval
display_menu();
printf("Wrong input. Please retry [1-8] : ");
fflush(stdin); // flushes the buffer
scanf("%d", &action);
}
if (DEBUG) printf("{action = %d}\n", action);
switch(action){
case TOKEN_ADD_NB_BEG:
insert_beginning_list(NULL, NULL);
break;
case TOKEN_ADD_NB_END:
insert_end_list(NULL, NULL);
break;
case TOKEN_ADD_NB_SPC:
insert_after_position(NULL, NULL, 0);
break;
case TOKEN_DEL_NB_SPC:
remove_element(NULL, 0);
break;
case TOKEN_SRT_LI_ASC:
sort(NULL);
break;
case TOKEN_DSP_LI_STD:
display(NULL);
break;
case TOKEN_RMX_LI_ALL:
destruct(NULL);
break;
}
}
if (DEBUG) printf("ChainedLists will close...\n");
return 0;
}
No preview for this file type
No preview for this file type
......@@ -11,3 +11,15 @@
<stdlib.h>
"tp3.h"
1510225412 source:c:\users\william\projets c\ai01_tp1\tp3.c
<stdio.h>
<stdlib.h>
"tp3.h"
1510225984 c:\users\william\projets c\ai01_tp1\tp3.h
1510225974 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="tp3.h" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="-2" zoom_2="0">
<Cursor>
<Cursor1 position="169" topLine="0" />
<Cursor1 position="1664" topLine="44" />
</Cursor>
</File>
<File name="main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="tp3.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="39" topLine="0" />
<Cursor1 position="327" topLine="21" />
</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.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="300" topLine="0" />
<Cursor1 position="337" topLine="11" />
</Cursor>
</File>
</CodeBlocks_layout_file>
......@@ -2,43 +2,65 @@
#include <stdlib.h>
#include "tp3.h"
/**
* A brief description. A more elaborate description
* @param type sometype a type argument.
* @return The test results
*/
void initialize(List* list){
println("INITIALIZE\n");
printf("INITIALIZE\n");
}
void insert_empty_list(List* list, char* str){
println("INSERT_EMPTY_LIST\n");
printf("INSERT_EMPTY_LIST\n");
}
void insert_beginning_list(List* list, char* str){
println("INSERT_BEGINNING_LIST\n");
printf("INSERT_BEGINNING_LIST\n");
}
void insert_end_list(List* list, char* str){
printf("INSERT_END_LIST\n");
}
int insert_after_position(List* list, char* str, int p){
printf("INSERT_AFTER_POSITION\n");
}
int remove_element(List* list, int p){
printf("REMOVE_ELEMENT\n");
}
int compare(char* str1, char* str2){
printf("COMPARE\n");
}
int sort(List* list){
printf("SORT\n");
}
void display(List* list){
printf("DISPLAY\n");
}
void destruct(List* list){
printf("DESTRUCT\n");
}
void display_menu(){
printf("******MAIN MENU***********************\n");
printf("**Choose an action by its key*********\n");
printf("**************************************\n\n");
printf("1 - Add a number at the beg. of the list\n");
printf("2 - Add a number at the end of the list\n");
printf("3 - Add a number at ...\n");
printf("4 - Delete a number from...\n");
printf("5 - Sort the list by ascending order\n");
printf("6 - Display the list\n");
printf("7 - Destroy the list\n");
printf("8 - Quit\n");
printf("**************************************\n\n");
}
#define N 5
#define DEBUG 1
#define TOKEN_ADD_NB_BEG 1
#define TOKEN_ADD_NB_END 2
#define TOKEN_ADD_NB_SPC 3
#define TOKEN_DEL_NB_SPC 4
#define TOKEN_SRT_LI_ASC 5
#define TOKEN_DSP_LI_STD 6
#define TOKEN_RMX_LI_ALL 7
#define TOKEN_PGM_GO_OUT 8
typedef struct element{
char* data;
......@@ -20,3 +29,5 @@ int compare(char* str1, char* str2);
int sort(List* list);
void display(List* list);
void destruct(List* list);
void display_menu();
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