infinityhost@interia.pl
Spis narzedzi niezbednych do wykonania zadania. Simple database with UI. sEdit.h main.c
Feel free to contact me
Dev C++ kompilator.
The following code is an example and it aims to demonstrate how to create a data structure and a user interface for it. It would be proper (though laborious) to use pointers in this project and dynamically allocate memory, so that the application could be perfectly adapted. Such programs are usually created with use of linked lists. We are starting work on our console database. To carry out this operation properly, we will need a compiler for this purpose. I believe that the appropriate one will be Dev C++, which we can download from the website thanks to the kindness of Embarcadero company. Dev C++ 6.3
Once we have the installation file available, we run the setup. After installing our compiler and launching it, we should see the following image in front of us:


Next, we create a new console application project.



We save the project files in a directory of our choice and compile them using the button F11 (compile & run)

We should see the following window appear:

Our current project code consists of these few lines. We save our project after each code modification.
      
        #include <stdio.h>

                                /* run this program using the console pauser or add your own getch, system("pause") or input loop */                        

        int main(int argc, char** argv) {
	                                 return 0;}

  
    

We have completed this stage.
The next thing we need to do is prepare our working environment.
Therefore, we add the header file #include and 2 functions that are essential in the Windows environment.
Function gotoxy takes two parameters, x and y, representing the row and column of the console cursor position. The function uses Windows Console API functions COORD and SetConsoleCursorPosition to move the console cursor to the specified position. By calling the gotoxy function with the desired coordinates, you can position the console cursor to a specific location on the screen. This can be useful for various tasks, such as printing text or graphics at specific locations in the console window.
      
void gotoxy(short x, short y) {COORD pos = {x, y};
                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}

    

The hidecursor function hides the console cursor by creating a CONSOLE_CURSOR_INFO structure and setting its size to 100 and visibility to false. It then sets the console cursor information using the SetConsoleCursorInfo function with the console output handle and cursor info as parameters. You can call this function to hide the cursor in your console application, which can be useful for various purposes such as creating cleaner user interfaces or preventing accidental cursor movements during user input.
      
void hidecursor(){   
					HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
   					CONSOLE_CURSOR_INFO info;  
    				        info.dwSize = 100;  
	 				info.bVisible = FALSE;
	    			        SetConsoleCursorInfo(consoleHandle, &info);}


    
At the moment, our code looks like this:
      
                  #include  <stdio.h>
                  #include  <windows.h >
                  #include  <conio.h >
                  #include  <string.h >

                            /**                        
                            * This function sets the cursor position in the console window                         
                            * to the specified                        
                            * x and y coordinates.                        
                            *                        
                            * @param x The x coordinate to set the cursor position to.                        
                            * @param y The y coordinate to set the cursor position to.                        
                            */                        
                  
                            void gotoxy(short x, short y) {
                            COORD pos = {x, y}; 
                            SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), pos);} 
                                             
                            /*                        
                            * Function Name: hidecursor                        
                            * Description: Hides the console cursor by setting its size to 100                        
                            * and visibility to false.                        
                            * Parameters: None                        
                            * Return: None                        
                            */                                                                     
                  void hidecursor(){ 
                                    HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); 
                                    CONSOLE_CURSOR_INFO info;
                                    info.dwSize = 100;
                                    info.bVisible = FALSE;
                                    SetConsoleCursorInfo(consoleHandle, &info);}
                                             
                                             

                  int main(int argc, char** argv){
                                                  return 0;}
                                   


    

The cursor should be hidden.

We can now test the functionality of both functions by displaying the text "Hello world!" in the center of the screen. The code will look like this:
      
#include  <stdio.h>
#include  <windows.h >

HANDLE console;
void gotoxy(short x, short y) {COORD pos = {x, y};
                                SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}
                                             
                                             
void hidecursor(){   
					HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
   					CONSOLE_CURSOR_INFO info;  
    				        info.dwSize = 100;  
	 				info.bVisible = FALSE;
    				        SetConsoleCursorInfo(consoleHandle, &info);}
                                             
                                             

int main(int argc, char** argv) {
                                               hidecursor();
                                               gotoxy(40,12);
                                               printf("Hello world!");
                                               gotoxy(0,22);

return 0;
}

    
The expected result is:
The text should be centered horizontally and vertically in the console window, and the cursor should be hidden. Next, we create a text file in the project directory called sEdit.h and save the following contents to it: sEdit.h
      
#include  <stdio.h>
#include  <windows.h >
#include  <conio.h >
#include  <string.h >



                  HANDLE console;
                  
                  void gotoxy(short x, short y) {COORD pos = {x, y};
                                        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}
                                             
                                             
                  void hidecursor(){   
					HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
   					CONSOLE_CURSOR_INFO info;  
    				        info.dwSize = 100;  
	 				info.bVisible = FALSE;
    				        SetConsoleCursorInfo(consoleHandle, &info);}

    


To draw a frame in the console window, we will create a function called "draw_frame". For now, we only need to draw a window with a predefined size and position. The code for this function is:
           
/**
 The draw_frame() function draws a simple frame or border on the console window.
It does this by first setting the starting position for the frame, and then 
using a series of gotoxy() and printf() statements to print the different characters 
that make up the frame.
 */


void draw_frame(){

					
					short start_x,start_y;
					start_x=1;start_y=8;
					
					gotoxy(start_x,1);
					printf("%c",201);
					gotoxy(25,1);
					printf("%c",187);
					for(int i=0;i<24;i++){
					gotoxy(i+start_x,1);
					printf("%c",205);}
					gotoxy(start_x,1);
					printf("%c",201);
					
					gotoxy(start_x,1+10);
					printf("%c",200);
					gotoxy(25,1+10);
					printf("%c",188);
					for(int i=0;<24;i++){
					gotoxy(i+start_x,1+10);
					printf("%c",205);}
					gotoxy(start_x,1+10);
					printf("%c",200);

					for(int i=1;i<10;i++){
					gotoxy(start_x,i+1);
					printf("%c",186);
					gotoxy(start_x+24,i+1);
					printf("%c",186);}}



    

If everything works as it should, we can test our program's functionality. The entire code is:

                                 #include  <stdio.h>
                                 #include  <windows.h >

                                 HANDLE console;
                                 void gotoxy(short x, short y) {COORD pos = {x, y};
                                             SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}
                                             

                                 void hidecursor(){   
					HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
   					CONSOLE_CURSOR_INFO info;  
    				        info.dwSize = 100;  
	 				info.bVisible = FALSE;
    				        SetConsoleCursorInfo(consoleHandle, &info);}

                                 void draw_frame(){

					short start_x,start_y;
					start_x=1;start_y=8;
					
					gotoxy(start_x,1);
					printf("%c",201);
					gotoxy(25,1);
					printf("%c",187);
					for(int i=0;i<24;i++){
					gotoxy(i+start_x,1);
					printf("%c",205);}
					gotoxy(start_x,1);
					printf("%c",201);
					
					gotoxy(start_x,1+10);
					printf("%c",200);
					gotoxy(25,1+10);
					printf("%c",188);
					for(int i=0;<24;i++){
					gotoxy(i+start_x,1+10);
					printf("%c",205);}
					gotoxy(start_x,1+10);
					printf("%c",200);

					for(int i=1;i<10;i++){
					gotoxy(start_x,i+1);
					printf("%c",186);
					gotoxy(start_x+24,i+1);
					printf("%c",186);}}                                           

                                 int main(int argc, char** argv) {
                                               hidecursor();
                                               draw_frame();
                                               gotoxy(0,22);

                                 return 0;
                                 }
result should be:

If the function works correctly, we modify it to display a window of a specified size at a specified location. The code for it is:

/*
The draw_frame function takes four integer parameters: x, y, width, 
and height. It uses these parameters to draw a rectangular frame with 
the specified width and height, starting at the position (x, y).*/



void draw_frame(int x, int y, int width, int height) {
                                 
                  int i, j;
                  gotoxy(x, y);
                  printf("%c", 201);                         // top-left corner                        
                  for (i = 1; i < width; i++) {
                  printf("%c", 205);}                         // horizontal line                        
                  
                  printf("%c", 187);                         // top-right corner                        
                  for (i = 1; i < height; i++) {
                  gotoxy(x, y + i);
                  printf("%c", 186);                         // vertical line                        
                  gotoxy(x + width, y + i);
                  printf("%c", 186);}                         // vertical line                        
    
                  gotoxy(x, y + height);
                  printf("%c", 200);                         // bottom-left corner                        
                  for (i = 1; i < width; i++) {
                  printf("%c", 205);}                         // horizontal line                        
    
                  printf("%c", 188);}                         // bottom-right corner                        


We add its code to the sEdit.h file. sEdit.h

#include  <stdio.h>
#include  <windows.h>
#include  <conio.h >
#include  <string.h >

                  HANDLE console;
                  
                  void gotoxy(short x, short y) {COORD pos = {x, y};
                                             SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}
                                             
                                             
                  void hidecursor(){   
					HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
   					CONSOLE_CURSOR_INFO info;  
    				        info.dwSize = 100;  
	 				info.bVisible = FALSE;
    				        SetConsoleCursorInfo(consoleHandle, &info);}

                  void draw_frame(int x, int y, int width, int height) {
                                 
					int i, j;
					gotoxy(x, y);
					printf("%c", 201); // top-left corner
					for (i = 1; i < width; i++) {
					printf("%c", 205);} // horizontal line
                  
					printf("%c", 187); // top-right corner
					for (i = 1; i < height; i++) {
					gotoxy(x, y + i);
					printf("%c", 186); // vertical line
					gotoxy(x + width, y + i);
					printf("%c", 186);} // vertical line
    
					gotoxy(x, y + height);
					printf("%c", 200); // bottom-left corner
					for (i = 1; i < width; i++) {
					printf("%c", 205);} // horizontal line
    
					printf("%c", 188);} // bottom-right corner

To test the correctness of our program, we modify the project code in the following way:


                  #include  "sEdit.h"
                  
                  int main(){
                  	
                  draw_frame(10,0,40,8);
                  draw_frame(52,0,40,8);
                  draw_frame(32,14,40,5);
                  
                  getch();
                  return 0;}

The result should be as follows:
In this part, we will create an array of names and display it in our frame. We will create a structure for this purpose, which will be a standard for creating future windows, and we will also include a couple of additional elements in it that we will surely find useful. In an ideal project, we would use pointers, but there is no such need here. After that we add 4 objects on the base of our structure.The first will be "main window" to keep, lets say, "names", the second one will be used for showing help, the third one will be used to modify content, and the fourth to show some additional content. Also we will need 4 multidimentional arrays. We add the following code at the end of the file sEdit.h:
                     
                      /* 
                      * Struct Name: window
                       * Description: A structure representing a graphical window on the screen.
                       * Members:
                       * - position_x: The horizontal position of the top-left corner of the window.
                       * - position_y: The vertical position of the top-left corner of the window.
                       * - width: The width of the window in pixels.
                       * - height: The height of the window in pixels.
                       * - size: The maximum number of items that can be displayed in the window.
                       * - selected_item_position: The index of the currently selected item in the window.
                       * - active: A flag indicating whether the window is currently active or not.
                       * - visible: A flag indicating whether the window is currently visible or not.
                       * - cursor_position: The position of the cursor in the window.
                       * - max_position: The maximum position of an item in the window.
                       * - names: A 2D character array containing the names of the items in the window.
                       * - color_scheme: A flag indicating the color scheme to use for the window.
                       */
           
           struct our_window {
                       int position_x;
                       int position_y;
                       int width;
                       int height;
                       int size;
                       int selected_item_position;
                       char active;
                       char visible;
                       int cursor_position;
                       int position;
                       int max_position;
                       char names[60][40];
                       char color_scheme;};

           
                       our_window new_window;
                       our_window help_window;
                       our_window modify_window;
                       our_window additional_window; 

                       char temporary[20][40];
                       char help_options[10][40];
                       char add_window[40];
                       char add_window_2[40];
                       char shopping_list[3][3][40];


Object-oriented programming in C++ would simplify our operations, but this is a C project, so instead of classes and constructors for creating objects, we will prepare a special function that will initialize them. It takes the following parameters: 1) the address of the window to be prepared, 2) x position, 3) y position, 4) width, 5) height, 6) the number of entries to be passed, 7) the address to the array of names, 8) color scheme, 9) whether the window is active - that is, whether to display the cursor (0 or 1), 10) whether the window is visible (0 or 1). This also needs to be placed in the sEdit.h file.
                  

              void prepare_window(struct our_window *new_window, int pos_x, int pos_y, int width, 
                                  int height, char names_count,  char *names,char sch,char act,char wid) {
					new_window->position_x=pos_x;
					new_window->position_y=pos_y;
					new_window->height=height;
					new_window->width=width;
					new_window->size=names_count;
					new_window->selected_item_position=0;
					new_window->cursor_position=0;
					new_window->color_scheme=0;
					new_window->max_position=names_count-height;
					new_window->active=act;					
					new_window->visible=wid;
					for(int i=0;i<60;i++){
					for(int j=0;j<40;j++){new_window->names[i][j]='\0';}}
					for(int i=0,k=0,j=0;i<200;i++,k++){
					if(names[k]!=36){new_window->names[j][i]=names[k];
					}else{    
					new_window->names[j][i]='\0';    
					if(i<40){k+=40-i-1;} 
					i=-1;j++;if(j==names_count){break;}}}}


Next step is adding 2 functions "hide_window" and "display_window". They will be used for displaying and hiding a window in the console, with a frame and some entries to be displayed inside. The hide_window() function sets the text color to black and prints a space character on each position inside the window to hide its contents, while the display_window() function sets the text color to white and displays the entries inside the window, along with an optional cursor on a selected entry.


              void hide_window(struct our_window target_window){

			// set the text color to black
			SetConsoleTextAttribute(console, 0x00);
			for(int i=target_window.position_x;i<target_window.width+target_window.position_x+1;i++){
			for(int j=target_window.position_y;j<target_window.height+target_window.position_y+1;j++){
			// move the cursor to the current position
			gotoxy(i, j);
			// print a space character to hide the contents of the window
			printf("%c", 32);}}} 

              void display_window(struct our_window target_window){
                    
                        //if flag visible of target_window is set to 1
                        if(target_window.visible==1){
                        struct our_window t=target_window;
                        draw_frame(t.position_x,t.position_y,t.width,t.height);

			// set the text color to white
			SetConsoleTextAttribute(console, 0x07); 
			int amount_to_display = 0;
    
			// check if the number of entries is greater than or equal to the size of the frame, 
			// or smaller, to know how many entries to display
			if(target_window.size >= target_window.height){
			amount_to_display = target_window.height - 1;
			} else {
			amount_to_display = target_window.size;}
    
    			
			// display the entries
			for(int i = 0; i < amount_to_display; i++){
			for(int j = 0; j < target_window.width - 1; j++){
			
			// move the cursor to the current position            
			gotoxy(target_window.position_x + 1 + j, target_window.position_y + 1 + i);
			
			// print the current entry            
			printf("%c", target_window.names[i][j]);}}

			
			// check if the cursor should be displayed
			if(target_window.active == 1){
			
			// set the text color to white on dark gray background        
			SetConsoleTextAttribute(console, 0x70);
			for(int j = 0; j < target_window.width - 1; j++){
			
			// move the cursor to the current position            
			gotoxy(target_window.position_x+1+j,target_window.position_y + 1 + target_window.cursor_position);
			
			// print the current entry with cursor
			printf("%c", target_window.names[target_window.position][j]);}}}} 

			
Also we create function to initalise our arrays:
		
                      
              void init(){
			  strcpy(temporary[0],"Andrew$");
			  strcpy(temporary[1],"John$");
			  strcpy(temporary[2],"Tom$");
			  strcpy(temporary[3],"Lucas$");
			  strcpy(temporary[4],"Joseph$");
			  strcpy(temporary[5],"Henry$");
			  strcpy(temporary[6],"Monica$");
			  strcpy(shopping_list[0][0],"Tonic$");
			  strcpy(shopping_list[0][1],"Chineese soup$");
			  strcpy(shopping_list[0][2],"Potatoes$");
		
			  strcpy(shopping_list[1][0],"Butter$");
			  strcpy(shopping_list[1][1],"Water$");
			  strcpy(shopping_list[1][2],"Smietana$");
		
			  strcpy(shopping_list[2][0],"Rzodkiewka$");
			  strcpy(shopping_list[2][1],"Cebula$");
			  strcpy(shopping_list[2][2],"Ziemniaki$");
			  
			  strcpy(help_options[0],"p - This window$");
			  strcpy(help_options[1],"z - Save to file$");
			  strcpy(help_options[2],"w - Read from file$");
			  strcpy(help_options[3],"e - Edit$");
			  
			  hidecursor();
                          console = GetStdHandle(STD_OUTPUT_HANDLE);

			  prepare_window(&new_window,30,1,30,5,7,&temporary[0][0],0,1,1);
                          prepare_window(&help_window,32,2,25,4,4,&help_options[0][0],0,0,0);
                          prepare_window(&modify_window,30,3,30,2,1,&add_window[0],0,1,0);
                          prepare_window(&additional_window,30,8,30,5,3,&shopping_list[0][0][0],0,0,0);
                          
			  display_window(new_window);}









The entire contents of the sEdit.h file should now look something like this: sEdit.h

            #include  <stdio.h>
            #include  <windows.h>
            #include  <conio.h >
            #include  <string.h >

            HANDLE console;
                  
            void gotoxy(short x, short y) {COORD pos = {x, y};
                        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}
                                             
                                             
            void hidecursor(){   
                        HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
                           CONSOLE_CURSOR_INFO info;  
    				        info.dwSize = 100;  
	 				info.bVisible = FALSE;
    				        SetConsoleCursorInfo(consoleHandle, &info);}

            void draw_frame(int x, int y, int width, int height) {
                                 
                        int i, j;
                        gotoxy(x, y);
                        printf("%c", 201); // top-left corner
                        for (i = 1; i < width; i++) {
                        printf("%c", 205);} // horizontal line
                  
                        printf("%c", 187); // top-right corner
                        for (i = 1; i < height; i++) {
                        gotoxy(x, y + i);
                        printf("%c", 186); // vertical line
                        gotoxy(x + width, y + i);
                        printf("%c", 186);} // vertical line
    
                        gotoxy(x, y + height);
                        printf("%c", 200); // bottom-left corner
                        for (i = 1; i < width; i++) {
                        printf("%c", 205);} // horizontal line
    
                        printf("%c", 188);} // bottom-right corner

            struct our_window {
                        int position_x;
                        int position_y;
                        int width;
                        int height;
                        int size;
                        int selected_item_position;
                        int position;
                        char active;
                        char visible;
                        int cursor_position;
                        int max_position;
                        char names[60][40];
                        char color_scheme;};

           
                        struct our_window new_window;
                        struct our_window help_window;
                        struct our_window modify_window;
                        struct our_window additional_window; 

                        char temporary[20][40];
                        char help_options[10][40];
                        char add_window[40];
                        char add_window_2[40];
                        char shopping_list[3][3][40];


            void prepare_window(struct our_window *new_window, int pos_x, int pos_y, int width, 
                        int height, char names_count,  char *names,char sch,char act,char wid){

                        new_window->position_x=pos_x;
                        new_window->position_y=pos_y;
                        new_window->height=height;
                        new_window->width=width;
                        new_window->size=names_count;
                        new_window->selected_item_position=0;
                        new_window->cursor_position=0;
                        new_window->color_scheme=0;
                        new_window->max_position=names_count-height;
                        new_window->active=act;                        
                        new_window->visible=wid;
                        for(int i=0;i<60;i++){
                        for(int j=0;j<40;j++){new_window->names[i][j]='\0';}}
                        for(int i=0,k=0,j=0;i<200;i++,k++){
                        if(names[k]!=36){new_window->names[j][i]=names[k];
                        }else{    
                        new_window->names[j][i]='\0';    
                        if(i<40){k+=40-i-1;} 
                        i=-1;j++;if(j==names_count){break;}}}}

            void hide_window(struct our_window target_window){

			// set the text color to black
			SetConsoleTextAttribute(console, 0x00);
			for(int i=target_window.position_x;i<target_window.width+target_window.position_x+1;i++){
			for(int j=target_window.position_y;j<target_window.height+target_window.position_y+1;j++){
			// move the cursor to the current position
			gotoxy(i, j);
			// print a space character to hide the contents of the window
			printf("%c", 32);}}} 

              void display_window(struct our_window target_window){
                        if(target_window.visible==1){
                        struct our_window t=target_window;
                        draw_frame(t.position_x,t.position_y,t.width,t.height);
			// set the text color to white
			SetConsoleTextAttribute(console, 0x07); 
			int amount_to_display = 0;
    
			// check if the number of entries is greater than or equal to the size of the frame, 
			// or smaller, to know how many entries to display
			if(target_window.size >= target_window.height){
			amount_to_display = target_window.height - 1;
			} else {
			amount_to_display = target_window.size;}
    
    			
			// display the entries
			for(int i = 0; i < amount_to_display; i++){
			for(int j = 0; j < target_window.width - 1; j++){
			
			// move the cursor to the current position            
			gotoxy(target_window.position_x + 1 + j, target_window.position_y + 1 + i);
			
			// print the current entry            
			printf("%c", target_window.names[i][j]);}}

			
			// check if the cursor should be displayed
			if(target_window.active == 1){
			
			// set the text color to white on dark gray background        
			SetConsoleTextAttribute(console, 0x70);
			for(int j = 0; j < target_window.width - 1; j++){
			
			// move the cursor to the current position            
			gotoxy(target_window.position_x+1+j,target_window.position_y + 1 + target_window.cursor_position);
			
			// print the current entry with cursor
			printf("%c", target_window.names[target_window.position][j]);}}}}


              void init(){
                        strcpy(temporary[0],"Andrew$");
                        strcpy(temporary[1],"John$");
                        strcpy(temporary[2],"Tom$");
                        strcpy(temporary[3],"Lucas$");
                        strcpy(temporary[4],"Joseph$");
                        strcpy(temporary[5],"Henry$");
                        strcpy(temporary[6],"Monica$");
                        strcpy(shopping_list[0][0],"Tonic$");
                        strcpy(shopping_list[0][1],"Chineese soup$");
                        strcpy(shopping_list[0][2],"Potatoes$");
		
                        strcpy(shopping_list[1][0],"Butter$");
                        strcpy(shopping_list[1][1],"Water$");
                        strcpy(shopping_list[1][2],"Smietana$");
		
                        strcpy(shopping_list[2][0],"Rzodkiewka$");
                        strcpy(shopping_list[2][1],"Cebula$");
                        strcpy(shopping_list[2][2],"Ziemniaki$");
                        
                        strcpy(help_options[0],"p - This window$");
                        strcpy(help_options[1],"z - Save to file$");
                        strcpy(help_options[2],"w - Read from file$");
                        strcpy(help_options[3],"e - Edit$");
                        
                        hidecursor();
                        console = GetStdHandle(STD_OUTPUT_HANDLE);

                        prepare_window(&new_window,30,1,30,5,7,&temporary[0][0],0,1,1);
                        prepare_window(&help_window,32,2,25,4,4,&help_options[0][0],0,0,0);
                        prepare_window(&modify_window,30,3,30,2,1,&add_window[0],0,1,0);
                        prepare_window(&additional_window,30,8,30,5,3,&shopping_list[0][0][0],0,0,0);
                          
                        display_window(new_window);}


let’s check if our application is properly designed so far. Now it displays the new window on the screen with display_window(new_window) function call. The gotoxy(25,0); printf("Press 'h' button to show or hide help window (press escape button to exit)") code line prints a message on the screen. Then the code enters a loop with a do-while statement. In each iteration of the loop, the program waits for user input with the getch() function call. If the user presses the 'h' button (ASCII code 104), the program checks if the help window is visible or not with the help_window.visible variable. If the help window is not visible, it sets its visibility to 1 and displays it on the screen with display_window(help_window). Otherwise, it sets the visibility to 0, hides it from the screen with hide_window(help_window), and displays the new window with display_window(new_window). The loop continues until the user presses the escape key (ASCII code 27).

#include  
#include "sEdit.h"

int main(int argc, char *argv[]) {
	                init();
            
                        
                        int option;
                        
                        gotoxy(25,0);
                        printf("Press 'h' button to show or hide help window (press escape button to exit)");
                       
						do{
                        option=getch();
                                  if(option==104){
                                                 if(help_window.visible==0){
                                                 help_window.visible=1;
                                                 display_window(help_window);
                                                 }else{
                                                 help_window.visible=0;hide_window(help_window);
                                                 display_window(new_window);}
                        }
                        }while(option!=27);
                        return 0;}
Our output:


Let's see if we can move our window, so let's test this small modification of a few lines of our code. This code reads keyboard input from the user and checks for arrow keys to move the window on the screen. It first displays a message on the console, informing the user that they can use the 'h' key to show or hide the help window and the escape key to exit the program. The code then enters a loop that reads keyboard input until the user presses the escape key. Within the loop, it checks for arrow keys and moves the new_window structure accordingly. The hide_window function is used to clear the console output where the window was displayed. The arrow keys are represented by the following values: left arrow (75), right arrow (77), up arrow (72), and down arrow (80).

#include  
#include "sEdit.h"

int main(int argc, char *argv[]) {
	                init();
            
                        
                        int option;
                        
                        gotoxy(25,0);
                        printf("Press 'h' button to show or hide help window (press escape button to exit)");
                       
			do{
                              option=getch();
                              if(option==75){hide_window(new_window);
					     new_window.position_x--;display_window(new_window);}
										
                              if(option==77){hide_window(new_window);
					     new_window.position_x++;display_window(new_window);}
					
                              if(option==72){hide_window(new_window);
					     new_window.position_y--;display_window(new_window);}
				    
                              if(option==80){hide_window(new_window);
					     new_window.position_y++;display_window(new_window);}
                        
                        }while(option!=27);
                        return 0;}



No problem, it moves around, but can it be expanded? The loop then waits for user input, and depending on the key pressed, it adjusts the width or height of the new_window object, which presumably represents a window on the screen. The hide_window function is used to hide the window while it is being resized, and then the display_window function is called to show the updated window after the resize is complete.

#include  
#include "sEdit.h"

int main(int argc, char *argv[]) {
	                init();
            
                        
                        int option;
                        
                        gotoxy(25,0);
                        printf("Press 'h' button to show or hide help window (press escape button to exit)");
                       
			do{
                              option=getch();
                              if(option==75){hide_window(new_window);
					     new_window.width--;display_window(new_window);}
										
                              if(option==77){hide_window(new_window);
					     new_window.width++;display_window(new_window);}
					
                              if(option==72){hide_window(new_window);
					     new_window.height--;display_window(new_window);}
				    
                              if(option==80){hide_window(new_window);
					     new_window.height++;display_window(new_window);}
                        
                        }while(option!=27);
                        return 0;}





To manipulate the cursor, we create 2 functions - 'move_cursor_down' and 'move_cursor_up'. Here is their code. The first function takes a pointer to a structure that represents the window as an argument. The function first checks if the cursor is not pointing to the last element in the window. If it is not, the function checks if the cursor is not at the border of the window height. If it is not, the function moves the cursor down by one position and displays the name of the element at the new cursor position. If the cursor is at the border of the window height, the function moves the cursor down by one position and displays the elements in the window accordingly.
 
             
                        
              void move_cursor_down(struct our_window *target_window) {
                        // if the cursor is not pointing to the last element
                        if (target_window->position < target_window->size - 1) {

                        // if the cursor position is not on the border of the frame height
                        if (target_window->cursor_position < target_window->height - 2) {
                        SetConsoleTextAttribute(console, 0x07);

                        // display the name of the element where the cursor is currently pointing to
                        for (int i = 0; i < target_window->width - 1; i++) {
                        gotoxy(target_window->position_x + 1 + i, target_window->position_y +
                        1 + target_window->cursor_position);
                        printf("%c", target_window->names[target_window->position][i]);}
            

                        // move the cursor down by one position
                        target_window->position++;
                        target_window->cursor_position++;

                        SetConsoleTextAttribute(console, 0x70);

                        // display the name of the element where the cursor is currently 
                        //pointing to, with highlighted text
                        for (int i = 0; i < target_window->width - 1; i++) {
                        gotoxy(target_window->position_x + 1 + i, target_window->position_y + 1
                        + target_window->cursor_position);
                        printf("%c", target_window->names[target_window->position][i]);}
                        
                        } else {

                        // move the cursor down by one position
                        target_window->position++;

                        int tmp = target_window->height - 2;

                        // calculate the starting position for displaying elements, 
                        // and display the elements on the window
                        int start = target_window->position - tmp;

                        SetConsoleTextAttribute(console, 0x07);

                        for (int j = 0; j < target_window->height - 1; j++) {
                        for (int i = 0; i < target_window->width - 1; i++) {
                        gotoxy(target_window->position_x + i + 1, target_window->position_y + j + 1);

                        // highlight the current cursor position
                        if (j == target_window->height - 2) {
                        SetConsoleTextAttribute(console, 0x70);}
                    
                        printf("%c", target_window->names[start + j][i]);}}}}}
And the second takes a pointer to a struct our_window as its argument. The function moves the cursor up one position in the window and updates the position and cursor_position members of the struct our_window. The if statement checks whether the window has any elements above the current position and whether the cursor is currently at the top of the window. If the cursor is not at the top of the window, the function updates the cursor position and the printf statements update the console window with the new cursor position and character. If the cursor is at the top of the window, the function updates the position of the window and scrolls the contents of the window up by one line.

              void move_cursor_up(struct our_window *target_window){
                        if (target_window->position > 0){
                        if (target_window->cursor_position > 0){
                        SetConsoleTextAttribute(console, 0x07);
                        for (int i = 0; i < target_window->width - 1; i++){
                        gotoxy(target_window->position_x + 1 + i, target_window->position_y + 
                        1 + target_window->cursor_position);
                        printf("%c", target_window->names[target_window->position][i]);}
                        
                        target_window->position = target_window->position - 1;
                        target_window->cursor_position--;
                        SetConsoleTextAttribute(console, 0x70);
                        for (int i = 0; i < target_window->width - 1; i++){
                        gotoxy(target_window->position_x + 1 + i, target_window->position_y +
                         1 + target_window->cursor_position);
                        printf("%c", target_window->names[target_window->position][i]);}

                        }else{
                        target_window->position--;
                        int tmp = target_window->height - 2;
                        int start = target_window->position;
                        
                        SetConsoleTextAttribute(console, 0x70);
                        for (int j = 0; j < target_window->height - 1; j++){
                        for (int i = 0; i < target_window->width - 1; i++){
                        gotoxy(target_window->position_x + i + 1, target_window->position_y + j + 1);
                        if (j > 0){ SetConsoleTextAttribute(console, 0x07); }
                        printf("%c", target_window->names[start + j][i]);}}}}}

Both of these codes are added to the end of the sEdycja.h file. We modify the main project file as follows: The code enters a do-while loop, which will repeat until the user presses the escape key. Inside the loop, the code reads a key input from the user using the getch() function and stores it in the option variable. If the key pressed is the down arrow key (ASCII code 80), the function move_cursor_down() is called with a pointer to a new_window object. If the key pressed is the up arrow key (ASCII code 72), the function move_cursor_up() is called with a pointer to the same new_window object. The loop continues until the user presses the escape key (ASCII code 27).

#include  
#include "sEdit.h"

int main(int argc, char *argv[]) {
	                init();
            
                        
                        int option;
                        
                        gotoxy(25,0);
                        printf("Use arrow keys to move cursor up or down (press escape button to exit)");
                       
			do{
                              option=getch();
                             
			      // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}
                        }
                        }while(option!=27);
                        return 0;}


We rebuild our project, click on the "Rebuild All (F12)" button and then click on "Compile and Run (F11)". We should see such a view:




Since we already have a window that we can navigate using arrow keys, it's time to add the ability to modify our data. Here's the function that accomplishes this task. It takes 4 arguments: a pointer to the location where the data strings are, the position on the x and y axes, and the length of the text to be modified.

              int change_entry(char *ptr, int poz_x, int poz_y, int length){
          
             
                  char text[60];
                  char *ptr2;
                  ptr2=ptr;
                  for(int i=0;i<length;i++){text[i]=*ptr2;ptr2++;}
                  int position=0;
                  hidecursor();
                  SetConsoleTextAttribute(console, 0x17);
             
                  for(int i=0;i<length;i++){gotoxy(poz_x+i,poz_y);printf("%c",text[i]);}
			 
                  SetConsoleTextAttribute(console, 0x70);
                  gotoxy(poz_x,poz_y);
                  printf("%c",text[position]);
                  gotoxy(poz_x,poz_y);
                  int char1 = 0;
                  int char2 = 0;
                  
                  while (1){
                        
                  char1 = getch();

                  if (char1 == 224)
                  {
                  char2 = getch();

                  switch (char2)
                  {
               
                  case 75:
                          if(position>0){
                          gotoxy(position+poz_x,0+poz_y);       	
                          SetConsoleTextAttribute(console, 0x17);
                          printf("%c",text[position]);
                          SetConsoleTextAttribute(console, 0x70);
                          position--;gotoxy(position+poz_x,0+poz_y); 
                          printf("%c",text[position]);}
                          break;			 
			 		 

                case 77:
                  
                          if(position<length-1){ 
                          gotoxy(position+poz_x,0+poz_y);
                          SetConsoleTextAttribute(console, 0x17);
                          printf("%c",text[position]);
                          SetConsoleTextAttribute(console, 0x70);
                          position++;gotoxy(position+poz_x,0+poz_y); 
                          printf("%c",text[position]);}
                          break;
                    
                          }
                  }else{
   

                    if(position<length && char1!=8  && char1!=13){
                          gotoxy(position+poz_x,0+poz_y);
                          text[position]=char1;
                          SetConsoleTextAttribute(console, 0x17);
                          printf("%c",char1);
                          if(position<length-1){
                          position++;
                          SetConsoleTextAttribute(console, 0x70);
                          gotoxy(position+poz_x,0+poz_y);
                          printf("%c",text[position]);
                  

                  }else{
                                 gotoxy(position+poz_x,0+poz_y);
                                 SetConsoleTextAttribute(console, 0x70);
                                 printf("%c",text[position]);}}
			 
                                 if(char1==8 && position>0){
			
                                            if(position==length-1){
                                            text[position]=32;
                                            SetConsoleTextAttribute(console, 0x17);
                                            gotoxy(position+poz_x,0+poz_y);
                                            printf("%c",text[position]);
                                            SetConsoleTextAttribute(console, 0x70);
                                            gotoxy(position+poz_x,0+poz_y);
                                            position--;
                                            gotoxy(position+poz_x,0+poz_y);
                                            printf("%c",text[position]);
                                            }else{
                                            
                                            text[position]=32;
                                            SetConsoleTextAttribute(console, 0x17);
                                            printf("%c",text[position]);
                                            SetConsoleTextAttribute(console, 0x70);
                                            position--;
                                            gotoxy(position+poz_x,0+poz_y);
                                            printf("%c",text[position]);}}
			 
			 
                    if(char1==8 && position==0){
                                            text[position]=32;
                                            gotoxy(position+poz_x,0+poz_y);
                                            SetConsoleTextAttribute(console, 0x70);
                                            printf("%c",text[position]);}
		
                    if(char1==27){return 0;}
                    if(char1==13){
                                            SetConsoleTextAttribute(console, 0x70);
                                            for(int i=0;i<length;i++){
                                            gotoxy(i+poz_x,poz_y);
                                            printf("%c",text[i]);
                                            *ptr=text[i];ptr++;}
                                            return 1;}}	
			 	
                    



                    gotoxy(position+poz_x,0+poz_y);}}


Now, in order to use this function multiple times, we save it at the end of the file "sEdycja.h". In our main file, we add this line inside the loop:

              if(option==101){
		              change_entry(&new_window.names[new_window.position][0],
		              new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};



The code looks like this:

#include  
#include "sEdit.h"

            int main(int argc, char *argv[]) {
	                init();
            
                        
                        int option;
                        SetConsoleTextAttribute(console, 0x07);
                        gotoxy(25,0);
                        printf("use 'e' key to modify item (press escape button to exit)");
                       
			do{
                              option=getch();
                             
			      // if 'e' key is pressed
			      if(option==101){
		                change_entry(&new_window.names[new_window.position][0],
		                new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};



                              // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}
                        }
                        }while(option!=27);
                        return 0;}

Result:



To add new item to our window we create such function:

		
            void add_new_item(){
                  
		SetConsoleTextAttribute(console, 0x07);
		modify_window.visible=1;
		modify_window.position_x=new_window.position_x;
		modify_window.position_y=new_window.position_y+2;
		
		gotoxy(new_window.position_x+1,new_window.position_y+1);printf("%s","        Write new name    ");
		display_window(modify_window);
		new_window.active=0;
								
		for(int i=0;i<39;i++){add_window[i]='\0';add_window_2[i]='\0';}
									
		// if there is string returned from function "change_entry" 
		if(change_entry(&add_window[0],new_window.position_x+1,new_window.position_y+3,29)==1){                
						
			hide_window(modify_window);
	
			int changed=0;
			strcpy(temporary[new_window.size],"");
			for(int u=0;u<39;u++){
			if(add_window[u]>30 && add_window[u]<123){
			add_window_2[u]=add_window[u];
			temporary[new_window.size][u]=add_window[u];
			}else{
								
			add_window_2[u]=36;add_window_2[u+1]='\0';
			strcpy(temporary[new_window.size],okno_dodawania2);
			SetConsoleTextAttribute(console, 0x70);
			

			//kopiujemy zapis z tablicy "okno_dodawania2" do naszego 
			//obiektu "new_window.names"(tablica z łacuchami znaków)
			for(int k=0;k<u;k++){  
					 new_window.names[new_window.size][k]=add_window_2[k];}
					 new_window.size++;
					 break;}}
							
					  }else{
					 hide_window(modify_window);} // ukrywamy okno dodawania
					 for(int u=0;u<40;u++){add_window[u]=32;
					 add_window_2[u]=32;}
				                     
					 add_window[39]='\0';
					 add_window_2[39]='\0';
					 // resetujemy ustawienia naszego okna
					 prepare_window(&modify_window,30,3,30,2,1,&add_window[0],0,1,0);
					 new_window.active=1;
								    
					 display_window(nowe);


And we modyfiy main project file.

#include "sEdit.h"

            int main(int argc, char *argv[]) {
	                init();
            
                        
                        int option;
                        SetConsoleTextAttribute(console, 0x07);
                        gotoxy(25,0);
                        printf("use 'a' key to add new item (press escape button to exit)");
                       
			do{
                              option=getch();
                             

			      // if 'a' key is pressed
			      if(option==97){add_new_item();}



			      // if 'e' key is pressed
			      if(option==101){
		                change_entry(&new_window.names[new_window.position][0],
		                new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};



                              // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}
                        }
                        }while(option!=27);
                        return 0;}


Result:



Removing elements will be done in the following way:


            void remove_item(){

                  char temporary_2[60][40]; // Declare a two-dimensional array of characters

                  // If there are elements to remove
                  if (new_window.size > 0) {

                  // If there are more than one elements to copy
                  if (new_window.size > 1) {

                  // Copy values from the object new_window.names to the temporary array temporary_2
                  for (int i = 0, k = 0; i < new_window.size; i++) {
                  if (i != new_window.position) {
                  strcpy(temporary_2[k], new_window.names[i]);
                  k++;}}
            

                  // Reset the current position of the element
                  new_window.position = 0;
                  new_window.cursor_position = 0;

                  // Decrement the number of elements
                  new_window.size--;

                  // Copy values from the temporary array temporary_2 back to the original array new_window.names
                  for (int i = 0; i < new_window.size; i++) {
                  strcpy(new_window.names[i], temporary_2[i]);}
            

                  // Reset the appearance of the window
                  hide_window(new_window);
                  display_window(new_window);

                  }else {    // If there is only one element

                  new_window.size--;
                  strcpy(new_window.names[0], "                           ");

                  // Reset the appearance of the window
                  hide_window(new_window);
                  display_window(new_window);}}}
Main project file:

#include "sEdit.h"

            int main(int argc, char *argv[]) {
	                init();
            
                        
                        int option;
                        SetConsoleTextAttribute(console, 0x07);
                        gotoxy(25,0);
                        printf("use 'delete' key to remove item (press escape button to exit)");
                       
			do{
                              option=getch();
                             

			      // if 'a' key is pressed
			      if(option==97){add_new_item();}

			      // if 'delete' key is pressed
			      if(option==83){remove_item();}


			      // if 'e' key is pressed
			      if(option==101){
		                change_entry(&new_window.names[new_window.position][0],
		                new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};



                              // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}
                        }
                        }while(option!=27);
                        return 0;}


Rezultatem będzie:



Sorting the elements will be quite simple, we just need to add a few lines to our sEdit.h code:
 
                                              
         void sort(int *asc_desc){
            
                 char temporary_2[60][40];
    
                 // Replace spaces with characters that the "strcmp" function can handle
                 for (int i = 0; i < new_window.size; i++) {
                        for (int j = 0; j < 40; j++) {
                            if (new_window.names[i][j] == 32) {
                            new_window.names[i][j] = 36;}}}
 
                 char tmp_tab[40];
                 if (*asc_desc == 0) { // if ascending sort is selected

                 // Sort the "new_window.names" array in ascending order
                 for (int i = 0; i < new_window.size; i++) {
                        for (int j = 0; j < new_window.size - 1; j++) {
                            if ((strcmp(new_window.names[j], new_window.names[j+1])) > 0) {
                            strcpy(tmp_tab, new_window.names[j]);
                            strcpy(new_window.names[j], "                           ");
                            strcpy(new_window.names[j], new_window.names[j+1]);
                            strcpy(new_window.names[j+1], "                         ");
                            strcpy(new_window.names[j+1], tmp_tab);}}}


                 // Replace the characters with spaces again
                 for (int i = 0; i < new_window.size; i++) {
                        for (int j = 0; j < 40; j++) {
                            if (new_window.names[i][j] == 36) {
                                   new_window.names[i][j] = 32;}}}

                 hide_window(new_window);
                 display_window(new_window);
                 *asc_desc = 1; // set sort order to ascending

                 }else{ // if descending sort is selected

                 // Sort the "new_window.names" array in descending order
                 for (int i = 0; i < new_window.size; i++) {
                        for (int j = 0; j < new_window.size - 1; j++) {
                            if ((strcmp(new_window.names[j], new_window.names[j+1])) < 0) {
                                   strcpy(tmp_tab, new_window.names[j]);
                                   strcpy(new_window.names[j], "                             ");
                                   strcpy(new_window.names[j], new_window.names[j+1]);
                                   strcpy(new_window.names[j+1], "                           ");
                                   strcpy(new_window.names[j+1], tmp_tab);}}}

                 // Replace the characters with spaces again
                 for (int i = 0; i < new_window.size; i++) {
                        for (int j = 0; j < 40; j++) {
                            if (new_window.names[i][j] == 36) {
                    new_window.names[i][j] = 32;}}}
                  hide_window(new_window);
                 display_window(new_window);
                 *asc_desc = 0;};}; // set sort order to descending
    

At the beginning of the main function, add an integer variable "sort_opt" (by changing its value we will alternate between sorting in ascending and descending order).
                                               
#include "sEdit.h"

            int main(int argc, char *argv[]) {
	                init();
            
                        int sort_opt=0;
                        int option;
                        SetConsoleTextAttribute(console, 0x07);
                        gotoxy(25,0);
                        printf("use 'a' key to add new item (press escape button to exit)");
                       
			do{
                              option=getch();
                             

			      // if 'a' key is pressed
			      if(option==97){add_new_item();}

			      // if 'delete' key is pressed
			      if(option==83){remove_item();}


			      // if the "s" key is pressed
			      if (option == 115) {sort(&sort_opt); }


			      // if 'e' key is pressed
			      if(option==101){
		                change_entry(&new_window.names[new_window.position][0],
		                new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};



                              // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}
                        }
                        }while(option!=27);
                        return 0;}


A wynik to:



We proceed to save our data. This action will be implemented by the following code:
    
         void save_data(){              
                     FILE *ptr_file;
                     ptr_file=fopen("names.dat","wb");
          
                     fprintf(ptr_file,"%d\n",new_window.size);
                     for(int i=0;i<new_window.size;i++){
          
                     for(int j=0;j<29;j++){
                     fprintf(ptr_file,"%c",new_window.names[i][j]);}
		  	
                     fprintf(ptr_file,"\n");}
	
                     fclose(ptr_file);}
Main project file:
                                               
#include "sEdit.h"

            int main(int argc, char *argv[]) {
	                init();
            
                        int sort_opt=0;
                        int option;
                        SetConsoleTextAttribute(console, 0x07);
                        gotoxy(25,0);
                        printf("use 'a' key to add new item (press escape button to exit)");
                       
			do{
                              option=getch();
                             

			      // if 'a' key is pressed
			      if(option==97){add_new_item();}

			      // if 'delete' key is pressed
			      if(option==83){remove_item();}


			      // if the "s" key is pressed
			      if (option == 115) {sort(&sort_opt); }


			      // if 'e' key is pressed
			      if(option==101){
		                change_entry(&new_window.names[new_window.position][0],
		                new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};

			      // if the "w" key is pressed
			      if (option == 119) {save_data(); }




                              // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}
                        }
                        }while(option!=27);
                        return 0;}


Result:



We are going to read our data now. This action will be performed by the following code:
       
	    void read_data(){
		        FILE *ptr_file;
		        ptr_file=fopen("names.dat","rb");
		        int size=0;
		        char tmp;
		        fscanf(ptr_file,"%d\n",&size);
		        for(int i=0;i<size;i++){
		        for(int j=0;j<29;j++){fscanf(ptr_file,"%c",&new_window.names[i][j]);}
		        new_window.names[i][29]='\0';
	
		        fscanf(ptr_file,"\n",&tmp);}
	     
		        new_window.size=size;
		        new_window.position=0;
		        new_window.cursor_position=0;
		        hide_window(new_window);
		        display_window(new_window);
		        fclose(ptr_file);
		        }            
		
Main project file:
       
#include "sEdit.h"

            int main(int argc, char *argv[]) {
	                init();
            
                        int sort_opt=0;
                        int option;
                        SetConsoleTextAttribute(console, 0x07);
                        gotoxy(25,0);
                        printf("use 'a' key to add new item (press escape button to exit)");
                       
			do{
                              option=getch();
                             

			      // if 'a' key is pressed
			      if(option==97){add_new_item();}

			      // if 'delete' key is pressed
			      if(option==83){remove_item();}


			      // if the "s" key is pressed
			      if (option == 115) {sort(&sort_opt); }


			      // if 'e' key is pressed
			      if(option==101){
		                change_entry(&new_window.names[new_window.position][0],
		                new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};

			      // if the "w" key is pressed
			      if (option == 119) {save_data(); }


			      // if the "r" key is pressed
			      if (option == 114) {read_data();}


                              // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}
                        }
                        }while(option!=27);
                        return 0;}


Result:



We will add support for additional elements in our database here, which will be a shopping list. At first we add to sEdit.h declaration of function that will refresh our windows without drawing a frame.
  
		 

void display_content(struct our_window target_window){
                    
                        //if flag visible of target_window is set to 1
                        if(target_window.visible==1){
                        struct our_window t=target_window;
                        /*draw_frame(t.position_x,t.position_y,t.width,t.height);*/

			// set the text color to white
			SetConsoleTextAttribute(console, 0x07); 
			int amount_to_display = 0;
    
			// check if the number of entries is greater than or equal to the size of the frame, 
			// or smaller, to know how many entries to display
			if(target_window.size >= target_window.height){
			amount_to_display = target_window.height - 1;
			} else {
			amount_to_display = target_window.size;}
    
    			
			// display the entries
			for(int i = 0; i < amount_to_display; i++){
			for(int j = 0; j < target_window.width - 1; j++){
			
			// move the cursor to the current position            
			gotoxy(target_window.position_x + 1 + j, target_window.position_y + 1 + i);
			
			// print the current entry            
			printf("%c", target_window.names[i][j]);}}

			
			// check if the cursor should be displayed
			if(target_window.active == 1){
			
			// set the text color to white on dark gray background        
			SetConsoleTextAttribute(console, 0x70);
			for(int j = 0; j < target_window.width - 1; j++){
			
			// move the cursor to the current position            
			gotoxy(target_window.position_x+1+j,target_window.position_y + 1 + 
			target_window.cursor_position);
			
			// print the current entry with cursor
			printf("%c", target_window.names[target_window.position][j]);}}}} 



Then will modify the 'main' function in the following way.
  
		 

#include "sEdit.h"

            int main(int argc, char *argv[]) {
	                init();
            
                        new_window.active=1;
                        hide_window(new_window);
                        prepare_window(&new_window,30,1,30,5,3,&temporary[0][0],0,1,1);
						
                        display_window(new_window);
                        int option;
                        int sort_opt=0;
                                                
                        additional_window.visible=1;
                        additional_window.position_y=15;
                        additional_window.position_x=new_window.position_x;
                        display_window(additional_window);
                        SetConsoleTextAttribute(console, 0x07);
                        gotoxy(25,0);
                        printf("use 'a' key to add new item (press escape button to exit)");
                       
			do{
                              option=getch();
                             

			      // if 'a' key is pressed
			      if(option==97){add_new_item();}

			      // if 'delete' key is pressed
			      if(option==83){remove_item();}


			      // if the "s" key is pressed
			      if (option == 115) {sort(&sort_opt); }


			      // if 'e' key is pressed
			      if(option==101){
		                change_entry(&new_window.names[new_window.position][0],
		                new_window.position_x+1,new_window.position_y+new_window.cursor_position+1,29);};

			      // if the "w" key is pressed
			      if (option == 119) {save_data(); }


			      // if the "r" key is pressed
			      if (option == 114) {read_data();}


                              // If down arrow key is pressed	
                              if(option==80){move_cursor_down(&new_window);}  

			      // If up arrow key is pressed
                              if(option==72){move_cursor_up(&new_window);}


                              // If down or up arrow key is pressed	
                              if(option==80 || option==72){
                                                  prepare_window(&additional_window,new_window.position_x,15,30,5,3,
                                                  &shopping_list[new_window.position][0][0],0,0,1);
									     
						  additional_window.visible=1;
										 
						  display_content(additional_window);


                              }

                        }
                        }while(option!=27);
                        return 0;}





Result: