Table is a library developed in the C language for creating dynamic tables.
The Table library allows you to easily create C language tables in CLI (Command Line Interface) format.
With this library, you can set the color of the table text and the left alignment of the table.
The table
function receives seven mandatory parameters, which are:
void table(size_t spacing, char *key_color, char *value_color, size_t key_attributes, char key[][MAXIMUM_STRING_LENGTH], size_t value_attributes, char value[][key_attributes][MAXIMUM_STRING_LENGTH]);
Below is an explanation of each parameter of the table
function.
- spacing: Number of spaces to the left of the table.
- key_color: Assign a color to the attributes of the table. If you leave it empty, it will be the default color. List of available colors:
white
,blue
,red
,green
,yellow
,magenta
andcyan
. - value_color: Assign a color to the values in the table. If you leave it empty, it will be the default color. List of available colors:
white
,blue
,red
,green
,yellow
,magenta
andcyan
. - key_attributes: Defines the number of attributes of the table (columns).
- key: It receives a two-dimensional vector containing the names of the attributes of the table.
- values_attributes: Sets the number of rows in the table (values).
- value: It receives a three-dimensional vector containing the values of the table.
This library has support for the Windows and GNU/Linux operating systems.
I have not been able to test it on macOS yet, but I believe it will work as well.
Below is an example of the use of the library.
#include <stdio.h>
#include <stdlib.h>
#include "table/table.h"
#define LINES 3
#define COLUMNS 6
#define MAXIMUM_STRING_LENGTH 50
int main(int argc, char *argv[]) {
char keys[COLUMNS][MAXIMUM_STRING_LENGTH] = { "ID", "Name", "Birth Date", "Telephone", "Email", "Password" };
char values[LINES][COLUMNS][MAXIMUM_STRING_LENGTH] = {
{ "1", "Lucas", "01/01/2000", "(11) 99999-9999", "lucas@gmail.com", "qwerty" },
{ "100", "Vanessa", "02/02/2000", "(11) 99999-9999", "vanessa@gmail.com", "qwerty" },
{ "1234", "Fernando", "03/03/2000", "(11) 99999-9999", "fernando@gmail.com", "qwerty" }
};
table(1, "blue", "", COLUMNS, keys, LINES, values);
return EXIT_SUCCESS;
}
Compiling the library example (GNU/Linux):
foo@bar:~$ gcc -o example example.c
Running the created executable:
foo@bar:~$ ./example
The image below illustrates the example table created with the library.
Developed by Lucas Araújo.
This software is MIT licensed.