C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
Loading...
Searching...
No Matches
main.c File Reference

Sorting CLI — pick an algorithm, sort either argv or stdin. More...

#include "sorts.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define MAX_WORD_LEN   256
 
#define MAX_WORDS   1024
 

Typedefs

typedef void(* string_sort_fn) (char **, size_t)
 

Functions

static string_sort_fn algo_from_name (const char *name)
 
int main (int argc, char *argv[])
 
static void print_array (char **arr, size_t n, const char *label)
 
static void print_usage (const char *prog)
 

Detailed Description

Sorting CLI — pick an algorithm, sort either argv or stdin.

Usage: sorting [–algo=NAME] [words ...] echo -e "banana\napple\ncherry" | sorting [–algo=NAME]

NAME ∈ {selection, insertion, bubble, quick, merge}. Default: selection.

Definition in file algorithms/sorting/main.c.

Macro Definition Documentation

◆ MAX_WORD_LEN

#define MAX_WORD_LEN   256

Definition at line 18 of file algorithms/sorting/main.c.

◆ MAX_WORDS

#define MAX_WORDS   1024

Definition at line 17 of file algorithms/sorting/main.c.

Typedef Documentation

◆ string_sort_fn

typedef void(* string_sort_fn) (char **, size_t)

Definition at line 20 of file algorithms/sorting/main.c.

Function Documentation

◆ algo_from_name()

static string_sort_fn algo_from_name ( const char *  name)
static

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ print_array()

static void print_array ( char **  arr,
size_t  n,
const char *  label 
)
static

Definition at line 43 of file algorithms/sorting/main.c.

Referenced by main().

◆ print_usage()

static void print_usage ( const char *  prog)
static

Definition at line 33 of file algorithms/sorting/main.c.

Referenced by main().