Skip to content

lucapwn/table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table

Table is a library developed in the C language for creating dynamic tables.

Badge Badge

Content

About

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]);

Attributes

Below is an explanation of each parameter of the table function.

  1. spacing: Number of spaces to the left of the table.
  2. 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 and cyan.
  3. 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 and cyan.
  4. key_attributes: Defines the number of attributes of the table (columns).
  5. key: It receives a two-dimensional vector containing the names of the attributes of the table.
  6. values_attributes: Sets the number of rows in the table (values).
  7. value: It receives a three-dimensional vector containing the values of the table.

Support

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.

Example

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", "[email protected]", "qwerty" },
        { "100", "Vanessa", "02/02/2000", "(11) 99999-9999", "[email protected]", "qwerty" },
        { "1234", "Fernando", "03/03/2000", "(11) 99999-9999", "[email protected]", "qwerty" }
    };

    table(1, "blue", "", COLUMNS, keys, LINES, values);

    return EXIT_SUCCESS;
}

Running

Compiling the library example (GNU/Linux):

foo@bar:~$ gcc -o example example.c

Running the created executable:

foo@bar:~$ ./example

Screenshot

The image below illustrates the example table created with the library.

Author

Developed by Lucas Araújo.

License

This software is MIT licensed.

About

Table is a library developed in the C language for creating dynamic tables.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages