Skip to content

Latest commit

 

History

History
73 lines (58 loc) · 1.62 KB

README.md

File metadata and controls

73 lines (58 loc) · 1.62 KB

Libgets

Libgets is a CS50-like C library with Nix flakes, designed for learning C and Nix flakes.

Table of Contents.

  1. How to use it in your devShell.
  2. To do List.

How to use it in your devShell.

  1. Add it to inputs in your flake.nix file.
inputs = {
    nixpkgs.url = "nixpkgs/nixos-24.05";
    libgets = {
        url = "github:aldosierra/libgets";
        inputs.nixpkgs.follows = "nixpkgs";
    };
};
  1. Add it to the devShell buildInputs.
devShells = {
    default = pkgs.mkShell {
        name = "sample-env";
        buildInputs = with pkgs; [ gcc libgets.packages."x86_64-linux".default ];
    };
};
  1. Import it on your c file.
#include "libgets.h"

int main(void) {
    char *name = GetString("What is your name? ");
    printf("Hi, %s\n", name);

    return 0;
}

Optionally you can add libgets to C_INCLUDE_PATH to include it on the standard system include directories, here is an example.

devShells = {
    default = pkgs.mkShell {
        name = "sample-env";
        buildInputs = with pkgs; [ gcc libgets.packages."x86_64-linux".default ];
        C_INCLUDE_PATH = "${libgets.packages.${system}.default}/include:$C_INCLUDE_PATH";
    };
};

This will work with both #include <...> and #include "...".

#include <libgets.h>

int main(void) {
    char *name = GetString("What is your name? ");
    printf("Hi, %s\n", name);

    return 0;
}

To do List.

  • Add a list of functions include it on this library.
  • Add options parameters for format messages.
  • Check for missing functions on the og cs50 library.