Skip to content

joshiayush/stlc

Introduction

stlc is a simple library without any dependencies providing support for StringStream, Vector, Map, and File System Routines.

The STL is a collection of reusable data structures and algorithms that provide a standardized way of writing efficient and reliable code in C. It can save time and effort for programmers by providing pre-built functions and structures that can be easily used in a variety of applications.

Installation

Clone the repository.

git clone https://github.com/joshiayush/stlc.git

Install libstlc

sudo chmod +x ./tools/install_libstlc.sh
./tools/install_libstlc.sh

Build tests

To build tests,

cmake -B build/ -S . -DBUILD_TESTS:BOOL=ON
cmake --build build/

Now run the tests,

./build/tests/tests  # Runs the unit tests

Usage

Creating and Initializing a StringStream

#include <stlc/bool.h>
#include <stlc/sstream/sstream.h>

int main() {
  // Creating an StringStream instance
  StringStream sstream;
  StringStreamStrInit(&sstream, "Hello, World!", -1);

  // Printing the contents of the StringStream
  PrintSstream(&sstream, FALSE);

  // Deallocating the StringStream
  StringStreamFree(&sstream);
}

Using StringStream for File I/O

#include <stdio.h>

#include <stlc/sstream/sstream.h>

int main() {
  // Creating an empty StringStream
  StringStream sstream;
  StringStreamInit(&sstream, -1);

  FILE* file = fopen("/path/to/file.txt", "r");

  // Read file contents into the stream
  StringStreamReadFile(&sstream, file, 0);

  // Return the resource acquired
  fclose(file);

  PrintSstream(&sstream, FALSE);
  printf("Total bytes stored %d.", sstream.length);
}

Contribution

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement", "bug", or "documentation". Don't forget to give the project a star! Thanks again!

Project stlc is hosted on GitHub. If you want to contribute changes please make sure to read the CONTRIBUTING.md file. You can also contribute changes to the CONTRIBUTING.md file itself.